From 88996ed4a3505872403f8285be228df9f7b15548 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 18 Sep 2024 16:38:54 +0200 Subject: [PATCH] Add support for rendering H/V Line and Span on multi_y (#6376) --- holoviews/plotting/bokeh/annotation.py | 5 +++++ .../tests/plotting/bokeh/test_annotationplot.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/holoviews/plotting/bokeh/annotation.py b/holoviews/plotting/bokeh/annotation.py index c97c44c95e..64f9fbdc4b 100644 --- a/holoviews/plotting/bokeh/annotation.py +++ b/holoviews/plotting/bokeh/annotation.py @@ -45,6 +45,11 @@ def __init__(self, element, **kwargs): raise ImportError(msg) super().__init__(element, **kwargs) + def _get_axis_dims(self, element): + if isinstance(element, (HLines, HSpans)): + return None, element.kdims[0], None + return element.kdims[0], None, None + def _init_glyph(self, plot, mapping, properties): self._plot_methods = {"single": self._methods[self.invert_axes]} return super()._init_glyph(plot, mapping, properties) diff --git a/holoviews/tests/plotting/bokeh/test_annotationplot.py b/holoviews/tests/plotting/bokeh/test_annotationplot.py index 4520435b2b..7ce2986936 100644 --- a/holoviews/tests/plotting/bokeh/test_annotationplot.py +++ b/holoviews/tests/plotting/bokeh/test_annotationplot.py @@ -267,6 +267,21 @@ def test_hlines_plot(self): assert list(source.data) == ["y"] assert (source.data["y"] == [0, 1, 2, 5.5]).all() + def test_hlines_plot_multi_y(self): + hlines = ( + HLines({"y1": [1, 2, 3]}, 'y1') * HLines({'y2': [3, 4, 5]}, 'y2') + ).opts(multi_y=True) + plot = bokeh_renderer.get_plot(hlines) + sp1, sp2 = plot.subplots.values() + y1_range = sp1.handles['y_range'] + assert y1_range.name == 'y1' + assert y1_range.start == 1 + assert y1_range.end == 3 + y2_range = sp2.handles['y_range'] + assert y2_range.name == 'y2' + assert y2_range.start == 3 + assert y2_range.end == 5 + def test_hlines_xlabel_ylabel(self): hlines = HLines( {"y": [0, 1, 2, 5.5], "extra": [-1, -2, -3, -44]}, vdims=["extra"]