I need to align a cartopy 2D map subplot with a 1D line subplot, using the following code:
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()
Both subplots have the same y- (latitude-) range and I expect the boxes of the two axes could align with each other. Is there a simple way to do this?