From 8ff076475fc75269707e0f3c7d431b8c287f2176 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Mon, 22 Apr 2019 09:22:26 -0400 Subject: [PATCH 1/2] plotly.offline.offline.utils -> plotly.utils --- holoviews/plotting/plotly/renderer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/plotly/renderer.py b/holoviews/plotting/plotly/renderer.py index 52f9964e5b..36d1821252 100644 --- a/holoviews/plotting/plotly/renderer.py +++ b/holoviews/plotting/plotly/renderer.py @@ -5,7 +5,8 @@ import param with param.logging_level('CRITICAL'): - from plotly.offline.offline import utils, get_plotlyjs, init_notebook_mode + from plotly import utils + from plotly.offline import get_plotlyjs, init_notebook_mode import plotly.graph_objs as go from ..renderer import Renderer, MIME_TYPES, HTML_TAGS From 4557972931c1e601481ed52a060bd29d3d151830 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Mon, 22 Apr 2019 09:23:30 -0400 Subject: [PATCH 2/2] Only add legend options to trace types that support them --- holoviews/plotting/plotly/element.py | 8 ++++++-- holoviews/plotting/plotly/util.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/holoviews/plotting/plotly/element.py b/holoviews/plotting/plotly/element.py index 9b5321f836..09aa0b5716 100644 --- a/holoviews/plotting/plotly/element.py +++ b/holoviews/plotting/plotly/element.py @@ -10,7 +10,8 @@ from ..plot import GenericElementPlot, GenericOverlayPlot from ..util import dim_range_key, dynamic_update from .plot import PlotlyPlot -from .util import STYLE_ALIASES, get_colorscale, merge_figure +from .util import ( + STYLE_ALIASES, get_colorscale, merge_figure, legend_trace_types) class ElementPlot(PlotlyPlot, GenericElementPlot): @@ -158,9 +159,12 @@ def graph_options(self, element, ranges, style): legend = element.label opts = dict( - showlegend=self.show_legend, legendgroup=element.group, name=legend, **self.trace_kwargs) + if self.trace_kwargs.get('type', None) in legend_trace_types: + opts.update( + showlegend=self.show_legend, legendgroup=element.group) + if self._style_key is not None: styles = self._apply_transforms(element, ranges, style) opts[self._style_key] = {STYLE_ALIASES.get(k, k): v diff --git a/holoviews/plotting/plotly/util.py b/holoviews/plotting/plotly/util.py index 5d4bd54a2a..1e9a9eaa60 100644 --- a/holoviews/plotting/plotly/util.py +++ b/holoviews/plotting/plotly/util.py @@ -79,6 +79,34 @@ 'scattermapbox': ['mapbox'] } +# trace types that support legends +legend_trace_types = { + 'scatter', + 'bar', + 'box', + 'histogram', + 'histogram2dcontour', + 'contour', + 'scatterternary', + 'violin', + 'waterfall', + 'pie', + 'scatter3d', + 'scattergeo', + 'scattergl', + 'splom', + 'pointcloud', + 'scattermapbox', + 'scattercarpet', + 'contourcarpet', + 'ohlc', + 'candlestick', + 'scatterpolar', + 'scatterpolargl', + 'barpolar', + 'area', +} + # Aliases - map common style options to more common names STYLE_ALIASES = {'line_width': 'width', 'alpha': 'opacity',