diff --git a/plotly/matplotlylib/mpltools.py b/plotly/matplotlylib/mpltools.py index 0a3206998ba..4875c2babdb 100644 --- a/plotly/matplotlylib/mpltools.py +++ b/plotly/matplotlylib/mpltools.py @@ -120,10 +120,10 @@ def merge_color_and_opacity(color, opacity): rgb_tup = hex_to_rgb(color) if opacity is None: - return "rgb {}".format(rgb_tup) + return "rgb{}".format(rgb_tup) rgba_tup = rgb_tup + (opacity,) - return "rgba {}".format(rgba_tup) + return "rgba{}".format(rgba_tup) def convert_va(mpl_va): diff --git a/plotly/matplotlylib/tests/test_renderer.py b/plotly/matplotlylib/tests/test_renderer.py index 81b7c222714..726dd507d38 100644 --- a/plotly/matplotlylib/tests/test_renderer.py +++ b/plotly/matplotlylib/tests/test_renderer.py @@ -233,3 +233,14 @@ def test_semitransparent_axes_background_preserved(): plotly_fig = tls.mpl_to_plotly(fig) assert plotly_fig.layout.plot_bgcolor == "rgba(26, 51, 76, 0.4)" + + +def test_line_color_is_valid_plotly_color(): + """Converted line colors are valid plotly color strings: plotly rejects + a space between 'rgba' and the opening parenthesis.""" + fig, ax = plt.subplots() + ax.plot([0, 1], [0, 1], color="red") + + plotly_fig = tls.mpl_to_plotly(fig) + + assert plotly_fig.data[0].line.color == "rgba(255, 0, 0, 1)"