我有 49 个 .nc 文件想要绘制(地图)。这些 nc 文件来自大气模拟。我感兴趣的变量是“脚”或脚印,带有经度、纬度、时间(73次)。我总结了几次得到2D地图。现在我正在尝试绘制所有 49 张地图,其标题反映了模拟位置 + 模拟时间。然而,我根本没有任何头衔。
我之前曾尝试过 plt.title('location' + Time[i]) 对于一个 nc 文件并且它有效。但是,我在对多个文件执行相同操作时遇到问题。怎么了?
file_list= sorted(glob.glob('*.nc'))
a_foot = None
Time = []
Foot= []
for file in sorted(glob.glob('*.nc')):
#print(file)
data= xr.open_dataset(file)
lon= data['lon']
lat= data['lat']
time= data['time']
foot= data['foot']
if a_foot is None:
a_foot=foot
else:
a_foot = foot
data.close()
#print(a_foot.data.min())
#print(a_foot.data.max())
for num in time:
actual_time= time.dt.strftime('%Y-%m-%d %H:%M:%S')
Time.append(actual_time)
ax= plt.axes(projection=ccrs.PlateCarree())
levels= [0.01, 0.05, 0.1, 0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, 0.55, 0.60]
plt.contourf(a_foot['lon'], a_foot['lat'],a_foot.sum(dim='time'),
levels=levels,
colors= ['mediumblue', 'deepskyblue', 'aqua', 'lightseagreen', 'mediumseagreen', 'limegreen', 'yellow', 'gold', 'orange', 'darkorange', 'tomato', 'orangered', 'red'],
) #when _r is added to cmap is used, it means reversed color pattern
ax.set_extent([-150, -143, 57.5, 72])
ax.coastlines()
gls= ax.gridlines(draw_labels=True)
gls.top_labels=False # suppress top labels
gls.right_labels=False # suppress right labels
plt.colorbar(label='Footprints, ppm (umol-1 m2 s)',location= 'right', shrink=0.5, format='%.0e', extend= "both")
#Add a marker at the receptor location
#ax.annotate("Fairbanks", xy=(-146.231483, 64.054333), size=8, color="black")
ax.plot(-146.231483, 64.054333, marker='o', markerfacecolor="None", markeredgecolor='black', markersize=6 )
plt.title('location,' + Time[i] )
plt.show()
您绝对不会将 i 设置为一个值,因此它始终为 0。 尝试将其声明为变量并通过循环递增它