【发布时间】:2021-08-07 12:33:40
【问题描述】:
我想知道是否可以将单个 netcdf 文件中的所有步骤绘制到单独的图中。
步骤 113 表示当前访问的数据是 2019 年 10 月 22 日的日期。第 0 步是 2019 年 7 月 1 日。总共有 135 个时间步长。这意味着我每天需要制作 135 张地图。
#x,y,u,v for the maps
X=Data.longitude; Y=Data.latitude;
U=Data.u10[113]; V=Data.v10[113];
pm2p5=Data.pm2p5[113];
这是我目前的代码。
import xarray as xr
import cartopy.crs as ccrs
from cartopy import feature as cf
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
Data=xr.open_dataset('PMs ECMWF2.nc')
#x,y,u,v for the maps
X=Data.longitude; Y=Data.latitude;
U=Data.u10[113]; V=Data.v10[113];
pm2p5=Data.pm2p5[113];
nlon, nlat = np.meshgrid(X,Y)
fig, ax = plt.subplots(figsize=(12, 12), dpi=300)
# Add Plotting the plot
ax=plt.subplot(111,projection=ccrs.PlateCarree())
# Add Plot features
ax.add_feature(cf.BORDERS, linewidth=.5, edgecolor="yellow")
ax.coastlines('50m', linewidth=0.8)
ax.add_feature(cf.LAKES)
ax.add_feature(cf.OCEAN)
ax.add_feature(cf.BORDERS, edgecolor="yellow")
ax.add_feature(cf.COASTLINE, edgecolor="yellow")
ax.add_feature(cf.RIVERS)
ax.gridlines()
#changing the location of the map
ax.set_extent([90, 141, 24, -10])
# Add gridlines, and set their font size
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=1, color='black', alpha=0.05, linestyle='-')
gl.top_labels = False
gl.left_labels = True
gl.right_labels = False
gl.xlines = True
gl.ylines = True
#colorbar
cmap = cm.get_cmap('jet') # Colour map coolwarm,hsv,bwr, seismic
# plotting the variables
pm2p5.plot(transform=ccrs.PlateCarree(), cbar_kwargs={'shrink': 0.5}, cmap=cmap)
plt.contour(nlon, nlat, pm2p5, fontsize=10,cmap=cmap) #plotting the contours
#plotting the quiver
ax.quiver(X[::3],Y[::3],U[::3,::3],V[::3,::3], color='white')
#plot title
#plt.title('Carbon Monoxide on October 22, 2019')
plt.show()
【问题讨论】:
-
您应该随着时间的推移制作一个循环,并为每个时刻生成一张地图。
-
@msi_gerva 你好!是的,那是我的计划,但我似乎找不到任何关于如何为此循环的指南,因为我看到的大多数 for 循环指令都是针对不同的文件而不是针对单个文件的。如果可以的话,你能帮我制作一个吗?