问题描述
可以通过这种方式直接从 xarray.Dataset
创建地图子图:(取自第二个示例 here)
p = air.isel(time=[0,4]).plot(
transform=ccrs.PlateCarree(),col="time",subplot_kws={"projection": ccrs.Orthographic(-80,35)})
for ax in p.axes.flat:
ax.coastlines()
ax.gridlines()
然而,这对应于使用标准的 matplotlib
子图,而例如将 AxesGrid
传递给 plot
函数会很好,最初可以更好地控制子图。这可能吗?
解决方法
您可以通过 ax
参数将自定义轴传递给 xarray 绘图函数,以便更好地控制定义轴的方式。
map_projection = ccrs.Orthographic(-80,35)
fig,axis = plt.subplots(2,2,figsize=(8,8),dpi=100,subplot_kw=dict(projection=map_projection))
for i,ax in enumerate(axis.flatten()):
air.isel(time=i).plot(ax=ax,transform=ccrs.PlateCarree())