Skip to content

Commit cc2aa83

Browse files
Set plot_bgcolor to white by default when converting from matplotlib figure
1 parent bf29422 commit cc2aa83

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

plotly/matplotlylib/renderer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def open_figure(self, fig, props):
8787
autosize=False,
8888
hovermode="closest",
8989
)
90+
self.plotly_fig["layout"].template.layout.plot_bgcolor = "white"
9091
self.mpl_x_bounds, self.mpl_y_bounds = mpltools.get_axes_bounds(fig)
9192
margin = go.layout.Margin(
9293
l=int(self.mpl_x_bounds[0] * self.plotly_fig["layout"]["width"]),

plotly/matplotlylib/tests/test_renderer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,12 @@ def test_multiple_traces_native_legend():
8484
assert plotly_fig.data[0].mode == "lines"
8585
assert plotly_fig.data[1].mode == "markers"
8686
assert plotly_fig.data[2].mode == "lines+markers"
87+
88+
89+
def test_plot_bgcolor_defaults_to_white():
90+
plt.figure()
91+
plt.plot([0, 1], [0, 1])
92+
93+
plotly_fig = tls.mpl_to_plotly(plt.gcf())
94+
95+
assert plotly_fig.layout.template.layout.plot_bgcolor == "white"

0 commit comments

Comments
 (0)