''''冷夜''' for name,groupmin in df.groupby("年"): # print(name)#1960-2012 groupmin.sort_values(by=['日最低温(0.1℃)'], inplace=True, ascending=False) #ascending=True从-1000到0到1000排列 Lye=groupmin[groupmin["日最低温(0.1℃)"] <groupmin["日最低温(0.1℃)"].quantile(0.1)] #取每年前10% # print( groupmin) b=list(Lye.count()) #年冷夜天数 # print('年冷夜天数:',b) #冬季 groupmin1L_1=Lye[Lye['月']==1] groupmin1L_2=Lye[Lye['月']==2] groupmin1L_12=Lye[Lye['月']==12] aL1=list(groupmin1L_1.count()) aL2=list(groupmin1L_2.count()) aL12=list(groupmin1L_12.count()) # AL=aL1+aL2+aL12 # print(AL) AL=aL1[0]+aL2[0]+aL12[0] # print(AL) #冬季暖夜 array = np.asarray(AL) # print(array) x=array print(x) fig,ax=plt.subplots() y=range(0,36) ax.plot(y,x,'ro-',lw=1,markersize=2,label='line1') plt.show() ,runfile('C:/Users/不想太忙/Desktop/实验1-4_2023年/shiyan11.py', wdir='C:/Users/不想太忙/Desktop/实验1-4_2023年') 37 Traceback (most recent call last): File ~\Desktop\实验1-4_2023年\shiyan11.py:427 ax.plot(y,x,'ro-',lw=1,markersize=2,label='line1') File D:\fanle\lib\site-packages\matplotlib\axes\_axes.py:1743 in plot lines = [*self._get_lines(*args, data=data, **kwargs)] File D:\fanle\lib\site-packages\matplotlib\axes\_base.py:273 in __call__ yield from self._plot_args(this, kwargs) File D:\fanle\lib\site-packages\matplotlib\axes\_base.py:399 in _plot_args raise ValueError(f"x and y must have same first dimension, but " ValueError: x and y must have same first dimension, but have shapes (36,) and (1,)
时间: 2024-03-03 12:53:17 浏览: 106
pandas基础使用教程.pdf
根据错误信息显示,发现 `x` 和 `y` 的维度不匹配。`x` 的维度是 `(36,)`,而 `y` 的维度是 `(1,)`,所以会报错。
可以通过以下代码修改:
```python
x = np.asarray([AL])
print(x)
fig, ax = plt.subplots()
y = range(0, 36)
ax.plot(y, x[0], 'ro-', lw=1, markersize=2, label='line1')
plt.show()
```
这里使用 `np.asarray()` 将 `AL` 转换为数组,并且将其外面套一个列表,以便 `x` 和 `y` 的维度匹配。
阅读全文