我正在尝试将我的421个连续日期(沿x轴显示)分组为一个月。因此,我不想将Janarary的31天贴上标签,而是希望这31天成为其他月份的一个标签,称为“ January / 2000”,依此类推。
我会附上一张图片,但我需要更高的代表。因此,y轴是纬度,x轴是每个月,作为一个时间序列。有什么帮助吗?
import numpy as np
from netCDF4 import Dataset
from matplotlib.dates import date2num
from datetime import datetime, timedelta
from netCDF4 import num2date, date2num, date2index
### by defining the directory pathway ###
expname='xnsbi'
inpath = 'E://Data Files (NetCDF)/'+expname+'/Monthly_AOD/'
mnames= ['0sep','0oct','0nov','0dec','1jan','1feb','1mar','1apr','1may','1jun','1jul', '1aug','1sep','1oct','1nov']
######################### Extracting the data for the plots
### Looping the variables needed to be extracted for the different months ###
Dates = []
array = []
for name in mnames:
infile= inpath+expname+'a_pd200'+name+'sAODtracersMDSJamesB.nc' # Complete
#the pathway to loop all files #
vn=Dataset(infile)
lon = vn.variables['longitude'][:]
lat = vn.variables['latitude'][:]
time = vn.variables['t'][:]
aod550 = vn.variables['aod'][:]
### Set the time and date of each plots ####
t_unit="days since 2000-09-01T00:00:00Z"
t_cal = "360_day"
dates =num2date(time,units=t_unit,calendar=t_cal)
fmt = '%m/%Y'
label = dates[0].strftime(fmt)
print(label)
ntime=len(time)
Mlon = np.mean(aod550,axis=1)
array.append(Mlon)
fig = plt.figure(figsize=(15.745,15), edgecolor='w')
在这里您可以看到连续421天。这在我的x轴上以421个不同的日期绘制(非常模糊)。
sdate=str(label)
Dates.append(sdate)
data = np.zeros((145,421)) # For the zonal mean
for i in range(421):
data[:,i] = array[i]
######## Construct the plot
cs = plt.contourf(Dates,lat,data,cmap='jet')