我需要使用以下代码将Cartopy 2D地图子图与1D线子图对齐:
import xarray as xr
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
air = xr.tutorial.open_dataset('air_temperature').air[0]
fig = plt.figure(figsize=(14,5))
ax1 = fig.add_subplot(121,
projection=ccrs.PlateCarree(central_longitude=180))
air.plot.pcolormesh(ax=ax1,
transform=ccrs.PlateCarree(),
cbar_kwargs={'orientation':'horizontal'})
ax1.coastlines()
ax1.set_extent((air.lon[0], air.lon[-1], air.lat[-1], air.lat[0]),
crs=ccrs.PlateCarree())
ax2 = fig.add_subplot(122)
air.mean('lon').plot(ax=ax2, y='lat')
plt.tight_layout()
两个子图都具有相同的y-(纬度)范围,我希望两个轴的框可以彼此对齐。有没有简单的方法可以做到这一点?
我从proplot找到了一个不错的解决方案: