CodeBreak 27/10/2021
Panel plot along the time axis
How to plot all time slices of a 3D dataset (time, latitude, longitude) in a single figure? We settled on this:
from itertools import chain
fig, axes = plt.subplot(7, 4, figsize=(20, 40),
subplot_kw={'projection': ccrs.PlateCarree()})
for t, ax in enumerate(chain(*axes)):
field = mydata.field.isel(time=t)
field.plot(ax=ax, x='latitude', y='longitude',
add_colorbar=False, transform=ccrs.PlateCarree())
ax.coastlines()
ax.set_title(mydata.time[t].item())
# add latitude ticks for first column
for j in range(7):
axes[j][0].set_yticks(np.linspace(-90, 90, 5, endpoint=True),
transform=ccrs.PlateCarree())
# add longitude ticks for final row
for j in range(4):
axes[-1][j].set_xticks(np.linspace(-180, 180, 5, endpoint=True),
transform=ccrs.PlateCarree())
plt.show()