Skip to content

Commit 1d57389

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

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

plotly/matplotlylib/renderer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def open_figure(self, fig, props):
7979
autosize=False,
8080
hovermode="closest",
8181
)
82+
self.plotly_fig["layout"].template.layout.plot_bgcolor = "white"
8283
self.mpl_x_bounds, self.mpl_y_bounds = mpltools.get_axes_bounds(fig)
8384
margin = go.layout.Margin(
8485
l=int(self.mpl_x_bounds[0] * self.plotly_fig["layout"]["width"]),

plotly/matplotlylib/tests/test_renderer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,13 @@ 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+
90+
def test_plot_bgcolor_defaults_to_white():
91+
plt.figure()
92+
plt.plot([0, 1], [0, 1])
93+
94+
plotly_fig = tls.mpl_to_plotly(plt.gcf())
95+
96+
assert plotly_fig.layout.template.layout.plot_bgcolor == "white"

0 commit comments

Comments
 (0)