Skip to content

Commit

Permalink
Allow subcoordinates to be drawn from NdOverlay dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 24, 2024
1 parent eb7ae9d commit 806a136
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
from bokeh.models.tools import Tool
from packaging.version import Version

from ...core import CompositeOverlay, Dataset, Dimension, DynamicMap, Element, util
from ...core import Dataset, Dimension, DynamicMap, Element, util
from ...core.options import Keywords, SkipRendering, abbreviated_exception
from ...core.overlay import CompositeOverlay, NdOverlay
from ...element import Annotation, Contours, Graph, Path, Tiles, VectorField
from ...streams import Buffer, PlotSize, RangeXY
from ...util.transform import dim
Expand Down Expand Up @@ -754,7 +755,7 @@ def _create_extra_axes(self, plots, subplots, element, ranges):

ax_specs, yaxes, dimensions = {}, {}, {}
subcoordinate_axes = 0
for el, sp in zip(element, self.subplots.values()):
for el, (sp_key, sp) in zip(element, self.subplots.items()):
ax_dims = sp._get_axis_dims(el)[:2]
if sp.invert_axes:
ax_dims[::-1]
Expand All @@ -765,7 +766,10 @@ def _create_extra_axes(self, plots, subplots, element, ranges):
if self._subcoord_overlaid:
if opts.get('subcoordinate_y') is None:
continue
ax_name = el.label
if element.kdims:
ax_name = ', '.join(d.pprint_value(k) for d, k in zip(element.kdims, sp_key))
else:
ax_name = el.label
subcoordinate_axes += 1
else:
ax_name = yd.name
Expand Down Expand Up @@ -1072,13 +1076,16 @@ def _axis_properties(self, axis, key, plot, dimension=None,
elif self._subcoord_overlaid and axis == 'y':
ticks, labels = [], []
idx = 0
for el, sp in zip(self.current_frame, self.subplots.values()):
for el, (sp_key, sp) in zip(self.current_frame, self.subplots.items()):
if not sp.subcoordinate_y:
continue
ycenter = idx if isinstance(sp.subcoordinate_y, bool) else 0.5 * sum(sp.subcoordinate_y)
idx += 1
ticks.append(ycenter)
labels.append(el.label)
if el.label or not self.current_frame.kdims:
labels.append(el.label)
else:
labels.append(', '.join(d.pprint_value(k) for d, k in zip(self.current_frame.kdims, sp_key)))
axis_props['ticker'] = FixedTicker(ticks=ticks)
if labels is not None:
axis_props['major_label_overrides'] = dict(zip(ticks, labels))
Expand Down Expand Up @@ -2048,6 +2055,9 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
if self._subcoord_overlaid:
if style_element.label in plot.extra_y_ranges:
self.handles['y_range'] = plot.extra_y_ranges.pop(style_element.label)
elif self.overlay_dims:
key = ', '.join(d.pprint_value(v) for d, v in self.overlay_dims.items())
self.handles['y_range'] = plot.extra_y_ranges.pop(key)

if self.apply_hard_bounds:
self._apply_hard_bounds(element, ranges)
Expand Down Expand Up @@ -3146,12 +3156,14 @@ def initialize_plot(self, ranges=None, plot=None, plots=None):
labels = self.hmap.last.traverse(lambda x: x.label, [
lambda el: isinstance(el, Element) and el.opts.get('plot').kwargs.get('subcoordinate_y', False)
])
if any(not label for label in labels):
if isinstance(self.hmap.last, NdOverlay):
pass
elif any(not label for label in labels):
raise ValueError(
'Every element wrapped in a subcoordinate_y overlay must have '
'a label.'
)
if len(set(labels)) == 1:
elif len(set(labels)) == 1:
raise ValueError(
'Elements wrapped in a subcoordinate_y overlay must all have '
'a unique label.'
Expand Down Expand Up @@ -3198,7 +3210,7 @@ def initialize_plot(self, ranges=None, plot=None, plots=None):
):
subcoord_y_glyph_renderers.append(glyph_renderer)

if self.subcoordinate_y:
if self.subcoordinate_y and plot:
# Reverse the subcoord-y renderers only.
reversed_renderers = subcoord_y_glyph_renderers[::-1]
reordered = []
Expand Down

0 comments on commit 806a136

Please sign in to comment.