【发布时间】:2020-07-03 13:03:23
【问题描述】:
我需要使用以下代码将 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-(纬度-)范围,我希望两个轴的框可以相互对齐。有没有简单的方法来做到这一点?
【问题讨论】:
标签: matplotlib python-xarray cartopy