From 1531bb16a1e9a66c7dd5734ca2cd3c16ca6996f9 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 9 Jul 2019 14:48:23 +0200 Subject: [PATCH] Fixed legends for PathPlot --- holoviews/plotting/bokeh/element.py | 7 ++++--- holoviews/plotting/bokeh/path.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py index f83becc4c1..5d431737fc 100644 --- a/holoviews/plotting/bokeh/element.py +++ b/holoviews/plotting/bokeh/element.py @@ -1030,12 +1030,11 @@ def _apply_transforms(self, element, data, ranges, style, group=None): else: factors = util.unique_array(val) kwargs['factors'] = factors - if factors is not None and getattr(self, 'show_legend', False): - new_style['legend'] = key cmapper = self._get_colormapper(v, element, ranges, dict(style), name=k+'_color_mapper', group=group, **kwargs) - if isinstance(cmapper, CategoricalColorMapper) and val.dtype.kind in 'ifMu': + categorical = isinstance(cmapper, CategoricalColorMapper) + if categorical and val.dtype.kind in 'ifMu': if v.dimension in element: formatter = element.get_dimension(v.dimension).pprint_value else: @@ -1044,6 +1043,8 @@ def _apply_transforms(self, element, data, ranges, style, group=None): data[k+'_str__'] = [formatter(d) for d in val] else: field = k + if categorical and getattr(self, 'show_legend', False): + new_style['legend'] = field key = {'field': field, 'transform': cmapper} new_style[k] = key diff --git a/holoviews/plotting/bokeh/path.py b/holoviews/plotting/bokeh/path.py index 9d5504f899..d3a33722ac 100644 --- a/holoviews/plotting/bokeh/path.py +++ b/holoviews/plotting/bokeh/path.py @@ -15,7 +15,7 @@ from .util import bokeh_version, multi_polygons_data -class PathPlot(ColorbarPlot): +class PathPlot(LegendPlot, ColorbarPlot): show_legend = param.Boolean(default=False, doc=""" Whether to show legend for the plot.""") @@ -143,7 +143,7 @@ def get_batched_data(self, element, ranges=None): return data, elmapping, style -class ContourPlot(LegendPlot, PathPlot): +class ContourPlot(PathPlot): show_legend = param.Boolean(default=False, doc=""" Whether to show legend for the plot.""")