Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subcoordinate_y: respect ylim #6190

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,14 @@ def _axis_props(self, plots, subplots, element, ranges, pos, *, dim=None,
l, b, r, t = b, l, t, r
if pos == 1 and self._subcoord_overlaid:
if isinstance(self.subcoordinate_y, bool):
offset = self.subcoordinate_scale / 2.
# This sum() is equal to n+1, n being the number of elements contained
# in the overlay with subcoordinate_y=True, as the traversal goes through
# the root overlay that has subcoordinate_y=True too since it's propagated.
v0, v1 = 0-offset, sum(self.traverse(lambda p: p.subcoordinate_y))-2+offset
if self.ylim and all(np.isfinite(val) for val in self.ylim):
v0, v1 = self.ylim
else:
offset = self.subcoordinate_scale / 2.
# This sum() is equal to n+1, n being the number of elements contained
# in the overlay with subcoordinate_y=True, as the traversal goes through
# the root overlay that has subcoordinate_y=True too since it's propagated.
maximlt marked this conversation as resolved.
Show resolved Hide resolved
v0, v1 = 0-offset, sum(self.traverse(lambda p: p.subcoordinate_y))-2+offset
else:
v0, v1 = 0, 1
else:
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ class GenericElementPlot(DimensionedPlot):
If specified, takes precedence over data and dimension ranges.""")

ylim = param.Tuple(default=(np.nan, np.nan), length=2, doc="""
User-specified x-axis range limits for the plot, as a tuple (low,high).
User-specified y-axis range limits for the plot, as a tuple (low,high).
If specified, takes precedence over data and dimension ranges.""")

zlim = param.Tuple(default=(np.nan, np.nan), length=2, doc="""
Expand Down
8 changes: 8 additions & 0 deletions holoviews/tests/plotting/bokeh/test_subcoordy.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def test_invisible_yaxis(self):
plot = bokeh_renderer.get_plot(overlay)
assert not plot.state.yaxis.visible

def test_overlay_set_ylim(self):
ylim = (1, 2.5)
overlay = Overlay([Curve(range(10), label=f'Data {i}').opts(subcoordinate_y=True) for i in range(2)])
overlay.opts(ylim=ylim)
plot = bokeh_renderer.get_plot(overlay)
y_range = plot.handles['y_range']
assert y_range.start, y_range.end == ylim

def test_axis_labels(self):
overlay = Overlay([Curve(range(10), label=f'Data {i}').opts(subcoordinate_y=True) for i in range(2)])
plot = bokeh_renderer.get_plot(overlay)
Expand Down
Loading