用于打印的切片数据集



当我试图将数据切片用于绘图时,我得到了所有的nan和以下错误消息:f"无效的索引器数组,没有整数dtype:{k!r}">

我的数据集包括2000年至2015年的月度数据,我只想获取2005年的月度值。

我使用的代码是:

k = temp.sel({'time':slice('2005')})
temp_seasonal=temp[k,0,276,275].groupby('time.month')
Katrina=plt.plot(temp_seasonal) #choose the last time (-1), the surface(0), and some rando indices for lat/lon
plt.ylabel(r'$theta$ ($degree$C)')
plt.xlabel('Time (month)')
plt.xlim(0,11)
plt.gca().set_xticks(np.arange(0,12))
plt.gca().set_xticklabels(['J','F','M','A','M','J','J','A','S','O','N','D'])
plt.title(r'Seasonal cycle of $theta$ ($degree$C) near Center of Major Hurricane Katrina');
plt.savefig("Katrina.pdf", bbox_inches='tight')

除了年份划分之外,所有的代码都有效,因为我使用以下代码得到了一张月平均温度的图:

temp_seasonal=temp[:,0,276,275].groupby('time.month').mean('time')
Katrina=plt.plot(temp_seasonal) #choose the last time (-1), the surface(0), and some rando indices for lat/lon
plt.ylabel(r'$theta$ ($degree$C)')
plt.xlabel('Time (month)')
plt.xlim(0,11)
plt.gca().set_xticks(np.arange(0,12))
plt.gca().set_xticklabels(['J','F','M','A','M','J','J','A','S','O','N','D'])
plt.title(r'Seasonal cycle of $theta$ ($degree$C) near Center of Major Hurricane Katrina');
plt.savefig("Katrina.pdf", bbox_inches='tight')

当然,发布后我马上就明白了!我需要删除我的切片线,并更改第二行,以反映我的数据集中48-60个月的指数:

temp_seasonal=temp[48:60,0,276,275].groupby('time.month').mean('time')

最新更新