Skip to content

Commit

Permalink
Account for overlaid elements when using subcoordinates_y (#5950)
Browse files Browse the repository at this point in the history
Co-authored-by: Demetris Roumis <[email protected]>
  • Loading branch information
hoxbro and droumis authored Oct 24, 2023
1 parent ad31eda commit bb81fe0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def _create_extra_axes(self, plots, subplots, element, ranges):
'axis_label_text_font_size': sp._fontsize('ylabel').get('fontsize'),
'major_label_text_font_size': sp._fontsize('yticks').get('fontsize')
},
'subcoordinate_y': subcoordinate_axes-1 if self._subcoord_overlaid else None
'subcoordinate_y': (subcoordinate_axes - 1) if self._subcoord_overlaid else None
}

for ydim, info in yaxes.items():
Expand Down Expand Up @@ -893,10 +893,12 @@ def _axis_properties(self, axis, key, plot, dimension=None,
axis_props['major_label_overrides'] = dict(zip(ticks, labels))
elif self._subcoord_overlaid and axis == 'y':
ticks, labels = [], []
for i, (el, sp) in enumerate(zip(self.current_frame, self.subplots.values())):
idx = 0
for el, sp in zip(self.current_frame, self.subplots.values()):
if not sp.subcoordinate_y:
continue
ycenter = i if isinstance(sp.subcoordinate_y, bool) else 0.5 * sum(sp.subcoordinate_y)
ycenter = idx if isinstance(sp.subcoordinate_y, bool) else 0.5 * sum(sp.subcoordinate_y)
idx += 1
ticks.append(ycenter)
labels.append(el.label)
axis_props['ticker'] = FixedTicker(ticks=ticks)
Expand Down
14 changes: 14 additions & 0 deletions holoviews/tests/plotting/bokeh/test_subcoordy.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ def test_overlaid_without_label_no_error(self):
with_span = overlay * VSpan(1, 2)
bokeh_renderer.get_plot(with_span)

def test_underlaid_ytick_alignment(self):
overlay = Overlay([Curve(range(10), label=f'Data {i}').opts(subcoordinate_y=True) for i in range(2)])
with_span = VSpan(1, 2) * overlay
plot = bokeh_renderer.get_plot(with_span)
# the yticks are aligned with their subcoordinate_y axis
assert plot.state.yaxis.ticker.ticks == [0, 1]

def test_overlaid_ytick_alignment(self):
overlay = Overlay([Curve(range(10), label=f'Data {i}').opts(subcoordinate_y=True) for i in range(2)])
with_span = overlay * VSpan(1, 2)
plot = bokeh_renderer.get_plot(with_span)
# the yticks are aligned with their subcoordinate_y axis
assert plot.state.yaxis.ticker.ticks == [0, 1]

def test_custom_ylabel(self):
overlay = Overlay([Curve(range(10), label=f'Data {i}').opts(subcoordinate_y=True) for i in range(2)])
overlay.opts(ylabel='Y label')
Expand Down

0 comments on commit bb81fe0

Please sign in to comment.