Skip to content

Commit 7023beb

Browse files
authored
compat: Matplotlib 3.11.0 (#6856)
1 parent 948ee3c commit 7023beb

4 files changed

Lines changed: 31 additions & 12 deletions

File tree

holoviews/plotting/mpl/element.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from ..plot import GenericElementPlot, GenericOverlayPlot
3131
from ..util import color_intervals, dim_range_key, process_cmap
3232
from .plot import MPLPlot, mpl_rc_context
33-
from .util import MPL_VERSION, EqHistNormalize, validate, wrap_formatter
33+
from .util import MPL_GE_3_11_0, MPL_VERSION, EqHistNormalize, validate, wrap_formatter
3434

3535

3636
class ElementPlot(GenericElementPlot, MPLPlot):
@@ -587,7 +587,7 @@ def _set_axis_ticks(self, axis, ticks, log=False, rotation=0):
587587
elif isinstance(ticks, (list, tuple)):
588588
labels = None
589589
if all(isinstance(t, tuple) for t in ticks):
590-
ticks, labels = zip(*ticks, strict=None)
590+
ticks, labels = zip(*ticks, strict=True)
591591
axis.set_ticks(ticks)
592592
if labels:
593593
axis.set_ticklabels(labels)
@@ -1211,13 +1211,25 @@ def _norm_kwargs(self, element, ranges, opts, vdim, values=None, prefix=""):
12111211
)
12121212
cmap = mpl_colors.ListedColormap(palette)
12131213

1214-
cmap = copy.copy(cmap)
1215-
if "max" in colors:
1216-
cmap.set_over(**colors["max"])
1217-
if "min" in colors:
1218-
cmap.set_under(**colors["min"])
1219-
if "NaN" in colors:
1220-
cmap.set_bad(**colors["NaN"])
1214+
if MPL_GE_3_11_0:
1215+
1216+
def _dict_to_rgba(name):
1217+
dct = colors.get(name)
1218+
if dct is None:
1219+
return None
1220+
return mpl_colors.to_rgba(dct["color"], alpha=dct.get("alpha"))
1221+
1222+
cmap = cmap.with_extremes(
1223+
over=_dict_to_rgba("max"), under=_dict_to_rgba("min"), bad=_dict_to_rgba("NaN")
1224+
)
1225+
else:
1226+
cmap = copy.copy(cmap)
1227+
if "max" in colors:
1228+
cmap.set_over(**colors["max"])
1229+
if "min" in colors:
1230+
cmap.set_under(**colors["min"])
1231+
if "NaN" in colors:
1232+
cmap.set_bad(**colors["NaN"])
12211233
opts[prefix + "cmap"] = cmap
12221234

12231235

holoviews/plotting/mpl/plot.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
GenericLayoutPlot,
3838
)
3939
from ..util import attach_streams, collate, displayable
40-
from .util import compute_ratios, fix_aspect, get_old_rcparams
40+
from .util import MPL_GE_3_11_0, compute_ratios, fix_aspect, get_old_rcparams
4141

4242

4343
@contextmanager
@@ -1048,6 +1048,10 @@ def _compute_gridspec(self, layout):
10481048
# Explicitly clear Matplotlib figures to avoid
10491049
# "Auto-removal of overlapping axes" warning.
10501050
self.handles["fig"].clf()
1051+
if MPL_GE_3_11_0:
1052+
# https://github.com/matplotlib/matplotlib/pull/27183
1053+
l, b, r, t = self.fig_bounds
1054+
self.handles["fig"].subplots_adjust(left=l, bottom=b, right=r, top=t)
10511055

10521056
# Situate all the Layouts in the grid and compute the gridspec
10531057
# indices for all the axes required by each LayoutPlot.

holoviews/plotting/mpl/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
MPL_GE_3_9_0 = MPL_VERSION >= (3, 9, 0)
4646
MPL_GE_3_10_0 = MPL_VERSION >= (3, 10, 0)
4747
MPL_GE_3_10_1 = MPL_VERSION >= (3, 10, 1)
48+
MPL_GE_3_11_0 = MPL_VERSION >= (3, 11, 0)
4849

4950

5051
def is_color(color):

holoviews/tests/plotting/matplotlib/test_renderer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,17 @@ def test_get_size_row_plot(self):
6262
with style.context("default"):
6363
plot = self.renderer.get_plot(self.image1 + self.image2)
6464
w, h = self.renderer.get_size(plot)
65+
assert w == 576
6566
# Depending on the backend the height may be slightly different
66-
assert (w, h) == (576, 257) or (w, h) == (576, 259)
67+
assert h in (257, 258, 259)
6768

6869
def test_get_size_column_plot(self):
6970
with style.context("default"):
7071
plot = self.renderer.get_plot((self.image1 + self.image2).cols(1))
7172
w, h = self.renderer.get_size(plot)
73+
assert w == 288
7274
# Depending on the backend the height may be slightly different
73-
assert (w, h) == (288, 509) or (w, h) == (288, 511)
75+
assert h in (509, 510, 511)
7476

7577
def test_get_size_grid_plot(self):
7678
grid = hv.GridSpace({(i, j): self.image1 for i in range(3) for j in range(3)})

0 commit comments

Comments
 (0)