From 164949e9664c01b74ee4946f19a504d3d82e9084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Fri, 29 Sep 2023 12:09:52 +0200 Subject: [PATCH] Add custom labels --- holoviews/plotting/bokeh/annotation.py | 3 ++- .../plotting/bokeh/test_annotationplot.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/bokeh/annotation.py b/holoviews/plotting/bokeh/annotation.py index 70e8e0d421..6c77964564 100644 --- a/holoviews/plotting/bokeh/annotation.py +++ b/holoviews/plotting/bokeh/annotation.py @@ -56,7 +56,8 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None): # Only force labels if no other ranges are set if self.overlaid and set(itertools.chain.from_iterable(ranges)) - {"HSpans", "VSpans", "VLines", "HLines"}: return figure - labels = "yx" if self.invert_axes else "xy" + labels = [self.xlabel or "x", self.ylabel or "y"] + labels = labels[::-1] if self.invert_axes else labels for ax, label in zip(figure.axis, labels): ax.axis_label = label return figure diff --git a/holoviews/tests/plotting/bokeh/test_annotationplot.py b/holoviews/tests/plotting/bokeh/test_annotationplot.py index ac8e1861f9..3525e80a1d 100644 --- a/holoviews/tests/plotting/bokeh/test_annotationplot.py +++ b/holoviews/tests/plotting/bokeh/test_annotationplot.py @@ -232,6 +232,15 @@ def test_hlines_plot(self): assert (source.data["y"] == [0, 1, 2, 5.5]).all() assert (source.data["extra"] == [-1, -2, -3, -44]).all() + def test_hlines_xlabel_ylabel(self): + hlines = HLines( + {"y": [0, 1, 2, 5.5], "extra": [-1, -2, -3, -44]}, vdims=["extra"] + ).opts(xlabel="xlabel", ylabel="xlabel") + plot = bokeh_renderer.get_plot(hlines) + assert isinstance(plot.handles["glyph"], BkHSpan) + assert plot.handles["xaxis"].axis_label == "xlabel" + assert plot.handles["yaxis"].axis_label == "xlabel" + def test_hlines_array(self): hlines = HLines(np.array([0, 1, 2, 5.5])) plot = bokeh_renderer.get_plot(hlines) @@ -412,6 +421,15 @@ def test_hspans_plot(self): assert (source.data["y1"] == [1, 4, 6.5]).all() assert (source.data["extra"] == [-1, -2, -3]).all() + def test_hspans_plot_xlabel_ylabel(self): + hspans = HSpans( + {"y0": [0, 3, 5.5], "y1": [1, 4, 6.5], "extra": [-1, -2, -3]}, vdims=["extra"] + ).opts(xlabel="xlabel", ylabel="xlabel") + plot = bokeh_renderer.get_plot(hspans) + assert isinstance(plot.handles["glyph"], BkHStrip) + assert plot.handles["xaxis"].axis_label == "xlabel" + assert plot.handles["yaxis"].axis_label == "xlabel" + def test_hspans_plot_invert_axes(self): hspans = HSpans( {"y0": [0, 3, 5.5], "y1": [1, 4, 6.5], "extra": [-1, -2, -3]}, vdims=["extra"]