Python 绘图NetCDF4月平均3D数据变量

Python 绘图NetCDF4月平均3D数据变量,python,matplotlib,np,netcdf4,Python,Matplotlib,Np,Netcdf4,我有这样的代码 # combine multiple years of .nc files mf = nc4.MFDataset("//porfiler03/gtdshare/IDL/wtypes/data/avgyears/slp*.nc") sealpm = mf.variables['slp'][:,:] print(mf) print(mf.variables.keys()) # get all variable names slpm = mf.variables['slp'] 我试着

我有这样的代码

# combine multiple years of .nc files
mf = nc4.MFDataset("//porfiler03/gtdshare/IDL/wtypes/data/avgyears/slp*.nc")
sealpm = mf.variables['slp'][:,:]
print(mf)
print(mf.variables.keys()) # get all variable names
slpm = mf.variables['slp']
我试着画出变量“slpm”的月平均值,它的维数是:4380x73x144。第一个维度(4380大小)以时间为单位,从数字格式转换为日期格式时如下所示:

timem = mf.variables['time']
time_convertm = nc4.num2date(timem[:], timem.units)
“time_convertm”的输出如下所示:

print(time_convertm)
[datetime.datetime(2017, 1, 1, 0, 0) datetime.datetime(2017, 1, 1, 6, 0)
datetime.datetime(2017, 1, 1, 12, 0) ...
datetime.datetime(2019, 12, 31, 6, 0)
datetime.datetime(2019, 12, 31, 12, 0)
datetime.datetime(2019, 12, 31, 18, 0)]
我使用以下代码绘制了一个月(2017年1月,如下所示)的图:

#average for current month accounting for days and 4 hr chunks per day
cmonth = mf.variables['slp'][0:31*4][:][:] #Single year first 124 rows for January 2017
cmonthav = cmonth.mean(axis=0)
#-- draw coastlines, state and country boundaries, edge of map
map.drawcoastlines()
map.drawstates()
map.drawcountries()
lons,lats= np.meshgrid(lon,lat) # for this dataset, longitude is 0 through 360, so you need to 
subtract 180 to properly display on map
x,y = map(lons,lats)
clevs = np.arange(960,1040,6)
cs = map.contour(x,y,cmonthav[:,:]/100.,clevs,cmap='jet',linewidths=1.)
最终,我需要一个如图所示的图,但在2017-2019年,平均为多个1月,而不仅仅是如图所示的一年。我看不出如何平均2017年、2018年和2019年的多个1月。谢谢你的想法