Skip to content

Commit b348c09

Browse files
authored
fix: norm and vmin/vmax in raster.py (#6889)
1 parent 5dd0669 commit b348c09

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

holoviews/plotting/mpl/raster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ def get_data(self, element, ranges, style):
216216

217217
def init_artists(self, ax, plot_args, plot_kwargs):
218218
locs = plot_kwargs.pop("locs", None)
219-
artist = ax.pcolormesh(*plot_args, **plot_kwargs)
220-
colorbar = self.handles.get("cbar")
221219
if "norm" in plot_kwargs: # vmin/vmax should now be exclusively in norm
222220
plot_kwargs.pop("vmin", None)
223221
plot_kwargs.pop("vmax", None)
222+
artist = ax.pcolormesh(*plot_args, **plot_kwargs)
223+
colorbar = self.handles.get("cbar")
224224
if colorbar and MPL_VERSION < (3, 1, 0):
225225
colorbar.set_norm(artist.norm)
226226
if hasattr(colorbar, "set_array"):

holoviews/tests/plotting/matplotlib/test_quadmeshplot.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import numpy as np
4+
from matplotlib.colors import Normalize
45

56
import holoviews as hv
67

@@ -57,3 +58,16 @@ def test_quadmesh_update_cbar(self):
5758
np.testing.assert_allclose(
5859
[cbar.vmin, cbar.vmax], [-1.7481711049213744, 1.7008913273857975]
5960
)
61+
62+
def test_quadmesh_with_norm(self):
63+
arr = np.array([[0, 1, 2], [3, 4, 5]])
64+
65+
qmesh = hv.QuadMesh(hv.Image(arr)).opts(norm=Normalize(), cmap="viridis")
66+
67+
# Before PR 6889, getting the plot would raise a ValueError from
68+
# matplotlib because vmin and vmax were passed alongside the norm.
69+
plot = mpl_renderer.get_plot(qmesh)
70+
71+
# Verify the plot handles were created and the norm is correctly applied
72+
artist = plot.handles["artist"]
73+
assert isinstance(artist.norm, Normalize)

0 commit comments

Comments
 (0)