Skip to content

Commit

Permalink
Add custom labels
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Sep 29, 2023
1 parent e3ae976 commit 164949e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion holoviews/plotting/bokeh/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions holoviews/tests/plotting/bokeh/test_annotationplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 164949e

Please sign in to comment.