0

我正在尝试绘制一些 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.

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

4

1 回答 1

0

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

通过添加修复它

将 numpy 导入为 np

并将我的 Y 数据定义为:AverageY = (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')

于 2017-10-10T10:37:23.283 回答