Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix colorbar min and max not being set on pcolormesh plots #870

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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