Skip to content

Commit

Permalink
Merge pull request #870 from MetOffice/868_respect_colorbar_range_pco…
Browse files Browse the repository at this point in the history
…lormesh

Fix colorbar min and max not being set on pcolormesh plots
  • Loading branch information
jfrost-mo authored Nov 4, 2024
2 parents 91a5367 + 3293cc1 commit 95f1470
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/CSET/operators/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,13 @@ def _plot_and_save_spatial_plot(
# Filled contour plot of the field.
plot = iplt.contourf(cube, cmap=cmap, levels=levels, norm=norm)
elif method == "pcolormesh":
try:
vmin = min(levels)
vmax = max(levels)
except TypeError:
vmin, vmax = None, None
# pcolormesh plot of the field.
plot = iplt.pcolormesh(cube, cmap=cmap, norm=norm)
plot = iplt.pcolormesh(cube, cmap=cmap, norm=norm, vmin=vmin, vmax=vmax)
else:
raise ValueError(f"Unknown plotting method: {method}")

Expand Down Expand Up @@ -324,8 +329,13 @@ def _plot_and_save_postage_stamp_spatial_plot(
# Filled contour plot of the field.
plot = iplt.contourf(member, cmap=cmap, levels=levels, norm=norm)
elif method == "pcolormesh":
try:
vmin = min(levels)
vmax = max(levels)
except TypeError:
vmin, vmax = None, None
# pcolormesh plot of the field.
plot = iplt.pcolormesh(member, cmap=cmap, norm=norm)
plot = iplt.pcolormesh(member, cmap=cmap, norm=norm, vmin=vmin, vmax=vmax)
else:
raise ValueError(f"Unknown plotting method: {method}")
ax = plt.gca()
Expand Down

0 comments on commit 95f1470

Please sign in to comment.