Difference between revisions of "CodeBreak 27/10/2021"
| Line 2: | Line 2: | ||
= <span style="font-size:13.999999999999998pt; font-family:Arial; color:#434343; background-color:transparent; font-weight:400; font-style:normal; font-variant:normal; text-decoration:none; vertical-align:baseline; white-space:pre; white-space:pre-wrap">Panel plot along the time axis</span> = | = <span style="font-size:13.999999999999998pt; font-family:Arial; color:#434343; background-color:transparent; font-weight:400; font-style:normal; font-variant:normal; text-decoration:none; vertical-align:baseline; white-space:pre; white-space:pre-wrap">Panel plot along the time axis</span> = | ||
| − | <span style="font-size:11pt; font-family:Arial; color:#000000; background-color:transparent; font-weight:400; font-style:normal; font-variant:normal; text-decoration:none; vertical-align:baseline; white-space:pre; white-space:pre-wrap">How to plot all time slices of a 3D dataset (time, latitude, longitude) in a single figure? We settled on this:</span> | + | <span style="font-size:11pt; font-family:Arial; color:#000000; background-color:transparent; font-weight:400; font-style:normal; font-variant:normal; text-decoration:none; vertical-align:baseline; white-space:pre; white-space:pre-wrap">How to plot all time slices of a 3D dataset (time, latitude, longitude) in a single figure? We settled on this:</span> |
| + | from itertools import chain | ||
| + | |||
fig, axes = plt.subplot(7, 4, figsize=(20, 40), | fig, axes = plt.subplot(7, 4, figsize=(20, 40), | ||
subplot_kw={'projection': ccrs.PlateCarree()}) | subplot_kw={'projection': ccrs.PlateCarree()}) | ||
Latest revision as of 20:38, 3 November 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()