Skip to content

Commit

Permalink
subcoordinate_y: respect ylim (#6190)
Browse files Browse the repository at this point in the history
Co-authored-by: Philipp Rudiger <[email protected]>
  • Loading branch information
maximlt and philippjfr committed Apr 23, 2024
1 parent 8507aab commit c1824f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
13 changes: 8 additions & 5 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,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, where n is the number of elements contained
# in the overlay with subcoordinate_y=True (including the the root overlay,
# which has subcoordinate_y=True due to option propagation)
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 @@ -138,6 +138,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

0 comments on commit c1824f7

Please sign in to comment.