diff --git a/holoviews/plotting/plotly/chart.py b/holoviews/plotting/plotly/chart.py index fcb2235588..bcb7c82ee9 100644 --- a/holoviews/plotting/plotly/chart.py +++ b/holoviews/plotting/plotly/chart.py @@ -198,8 +198,7 @@ class BarPlot(BarsMixin, ElementPlot): show_legend = param.Boolean(default=True, doc=""" Whether to show legend for the plot.""") - - style_opts = ['visible'] + style_opts = ['visible', 'color'] selection_display = PlotlyOverlaySelectionDisplay() @@ -282,6 +281,12 @@ def get_data(self, element, ranges, style, **kwargs): return bars + def graph_options(self, element, ranges, style, **kwargs): + if 'color' in style: + style['marker_color'] = style.pop('color') + opts = super().graph_options(element, ranges, style, **kwargs) + return opts + def init_layout(self, key, element, ranges, **kwargs): layout = super().init_layout(key, element, ranges) stack_dim = None diff --git a/holoviews/tests/plotting/plotly/test_barplot.py b/holoviews/tests/plotting/plotly/test_barplot.py index bf0a7ea717..3d0fb34433 100644 --- a/holoviews/tests/plotting/plotly/test_barplot.py +++ b/holoviews/tests/plotting/plotly/test_barplot.py @@ -155,3 +155,10 @@ def test_bar_group_stacked(self): plot = self._get_plot_state(bars) np.testing.assert_equal(set(plot['data'][0]['x']), set(pets)) np.testing.assert_equal(plot['data'][0]['y'], np.array([8, 7, 6, 7])) + + def test_bar_color(self): + data = pd.DataFrame({"A": range(5)}) + bars = Bars(data).opts(color="gold") + fig = self._get_plot_state(bars) + data = fig["data"][0] + assert data["marker"]["color"] == "gold"