From f67319bd357b7cd3e26be3233ad6a12985dfa957 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 10 Jun 2024 11:52:29 +0200 Subject: [PATCH 1/3] Disable batching when subcoordinate_y is enabled --- holoviews/plotting/bokeh/element.py | 5 +++++ holoviews/plotting/plot.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py index ae500ffb10..1647505e8e 100644 --- a/holoviews/plotting/bokeh/element.py +++ b/holoviews/plotting/bokeh/element.py @@ -2113,6 +2113,7 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None): self.handles['xaxis'], self.handles['yaxis'] = axes self.handles['x_range'], self.handles['y_range'] = plot_ranges if self._subcoord_overlaid: + if style_element.label in plot.extra_y_ranges: self.handles['subcoordinate_y_range'] = plot.y_range self.handles['y_range'] = plot.extra_y_ranges.pop(style_element.label) @@ -3004,6 +3005,10 @@ def _y_range_type(self): return v._y_range_type return self._y_range_type + @property + def _is_batched(self): + return super()._is_batched and not self.subcoordinate_y + def _process_legend(self, overlay): plot = self.handles['plot'] subplots = self.traverse(lambda x: x, [lambda x: x is not self]) diff --git a/holoviews/plotting/plot.py b/holoviews/plotting/plot.py index 774842989f..6ac6ef052e 100644 --- a/holoviews/plotting/plot.py +++ b/holoviews/plotting/plot.py @@ -1797,10 +1797,14 @@ def _apply_compositor(self, holomap, ranges=None, keys=None, dimensions=None): collapsed = Compositor.collapse(holomap, (ranges, frame_ranges.keys()), mode='display') return collapsed + @property + def _is_batched(self): + return self.batched and type(self.hmap.last) is NdOverlay + def _create_subplots(self, ranges): # Check if plot should be batched ordering = util.layer_sort(self.hmap) - batched = self.batched and type(self.hmap.last) is NdOverlay + batched = self._is_batched if batched: backend = self.renderer.backend batchedplot = Store.registry[backend].get(self.hmap.last.type) From 9fab2c74404ca64506136ce88b185e16294a3aaa Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 10 Jun 2024 15:06:25 +0200 Subject: [PATCH 2/3] Add test --- holoviews/tests/core/test_layers.py | 8 +++++++- holoviews/tests/plotting/bokeh/test_overlayplot.py | 14 +++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/holoviews/tests/core/test_layers.py b/holoviews/tests/core/test_layers.py index 35a21e2613..5eb0acb69b 100644 --- a/holoviews/tests/core/test_layers.py +++ b/holoviews/tests/core/test_layers.py @@ -2,7 +2,7 @@ import numpy as np -from holoviews import Element, NdOverlay +from holoviews import Curve, Element, NdOverlay, Overlay class CompositeTest(unittest.TestCase): @@ -29,6 +29,12 @@ def test_overlay_iter(self): for el, v in zip(overlay, views): self.assertEqual(el, v) + def test_overlay_iterable(self): + # Related to https://github.com/holoviz/holoviews/issues/5315 + c1 = Curve([0, 1]) + c2 = Curve([10, 20]) + Overlay({'a': c1, 'b': c2}.values()) + def test_overlay_integer_indexing(self): overlay = NdOverlay(list(enumerate([self.view1, self.view2, self.view3]))) self.assertEqual(overlay[0], self.view1) diff --git a/holoviews/tests/plotting/bokeh/test_overlayplot.py b/holoviews/tests/plotting/bokeh/test_overlayplot.py index 1678ce53ec..bfca27b19b 100644 --- a/holoviews/tests/plotting/bokeh/test_overlayplot.py +++ b/holoviews/tests/plotting/bokeh/test_overlayplot.py @@ -278,11 +278,15 @@ def test(x): _, vline_plot = plot.subplots.values() assert vline_plot.handles['glyph'].location == 1 - def test_overlay_iterable(self): - # Related to https://github.com/holoviz/holoviews/issues/5315 - c1 = Curve([0, 1]) - c2 = Curve([10, 20]) - Overlay({'a': c1, 'b': c2}.values()) + def test_ndoverlay_subcoordinate_y_no_batching(self): + overlay = NdOverlay({ + i: Curve(np.arange(10)*i).opts(subcoordinate_y=True) for i in range(10) + }).opts(legend_limit=1) + plot = bokeh_renderer.get_plot(overlay) + + assert plot.batched == False + assert len(plot.subplots) == 10 + class TestLegends(TestBokehPlot): From 2a0a6fb7602561f599e0175689c81ab3939168b8 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 10 Jun 2024 15:07:37 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- holoviews/plotting/bokeh/element.py | 1 - 1 file changed, 1 deletion(-) diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py index 1647505e8e..8015bd1e60 100644 --- a/holoviews/plotting/bokeh/element.py +++ b/holoviews/plotting/bokeh/element.py @@ -2113,7 +2113,6 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None): self.handles['xaxis'], self.handles['yaxis'] = axes self.handles['x_range'], self.handles['y_range'] = plot_ranges if self._subcoord_overlaid: - if style_element.label in plot.extra_y_ranges: self.handles['subcoordinate_y_range'] = plot.y_range self.handles['y_range'] = plot.extra_y_ranges.pop(style_element.label)