Python 虹膜图平均 NetCDF 数据

Python Iris plot average NetCDF data

我正在尝试绘制一些 NetCDF 文件的输出以及所有文件的平均值。我已经成功绘制了 NetCDF 文件本身,如下所示(其中 CCCmaYR_mean、CLMcomYR_mean、DMIYR_mean、KNMIYR_mean、MPIYR_mean、SMHIYR_mean、 CRUYR_mean和UDelYR_mean都是预定义的NetCDF文件)

#PART 4: PLOT LINE GRAPH
#set x-axis ticks                                                                                            
plt.xticks(range(12), calendar.month_abbr[0:12]) 

#assign the line colours and set x axis to 'month' rather than 'time'
qplt.plot(CCCmaYR_mean.coord('month_number'), CCCmaYR_mean, label='CanRCM4_ERAINT', lw=1.5, color='blue')
qplt.plot(CLMcomYR_mean.coord('month_number'), CLMcomYR_mean, label='CCLM4-8-17_ERAINT', lw=1.5, color='green')
qplt.plot(DMIYR_mean.coord('month_number'), DMIYR_mean, label='HIRHAM5_ERAINT', lw=1.5, color='red')
qplt.plot(KNMIYR_mean.coord('month_number'), KNMIYR_mean, label='RACMO22T_ERAINT', lw=1.5, color='cyan')
qplt.plot(MPIYR_mean.coord('month_number'), MPIYR_mean, label='REMO2009_ERAINT', lw=1.5, color='magenta')
qplt.plot(SMHIYR_mean.coord('month_number'), SMHIYR_mean, label='RCA4_ERAINT', lw=1.5, color='yellow')   
qplt.plot(CRUYR_mean.coord('month_number'), CRUYR_mean, label='Observed_CRU', lw=2, color='grey')
qplt.plot(UDelYR_mean.coord('month_number'), UDelYR_mean, label='Observed UDel', lw=2, color='grey', linestyle = '--')

#set a title for the y axis
plt.ylabel('Near-Surface Temperature (degrees Celsius)')

#create a legend and set its location to under the graph
plt.legend(loc="upper center", bbox_to_anchor=(0.5,-0.05), fancybox=True, shadow=True, ncol=2)

#create a title
plt.title('Mean Near Surface Temperature for Malawi by Month 1990-2008', fontsize=11)   

#add grid lines
plt.grid()

#save the image of the graph and include full legend
#plt.savefig('ERAINT_Temperature_LineGraph_Monthly', bbox_inches='tight')

#show the graph in the console
iplt.show() 

这给了我下面的图表:

为了创建平均值,我添加了这段代码:

 ##Create an average CORDEX and some x coordinates
AverageY = (CCCmaYR_mean.data + CLMcomYR_mean.data + DMIYR_mean.data + KNMIYR_mean.data + MPIYR_mean.data + SMHIYR_mean.data)/6.
AverageX = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

然后将以下内容与上面显示的其他 qplot.plot 代码包含在一起。

qplt.plot(AverageX, AverageY, label='AverageY', lw=1.5, color='black')

这给了我以下错误:

AttributeError: 'list' object has no attribute 'ndim'

我也试过定义 AverageX 如下:

AverageX = np.arange(0,12,1)

这给出了这个错误:

TypeError: Plot arguments must be cubes or coordinates.

我确定我正在做一些非常愚蠢的事情,但是有人可以告诉我它是什么吗!?

@RuthC 在以上评论中的回答。

通过添加

修复了它

将 numpy 导入为 np

并将我的 Y 数据定义为: 平均 Y = (CCCmaYR_mean.data + CLMcomYR_mean.data + DMIYR_mean.data + KNMIYR_mean.data + MPIYR_mean.data + SMHIYR_mean.data)/6.

我的 X 数据为: AverageX = np.arange(1,13,1)

然后将其绘制为: plt.plot(AverageX, AverageY, label='Average', lw=1.5, color='black')