Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plotly/matplotlylib/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def open_figure(self, fig, props):
autosize=False,
hovermode="closest",
)
self.plotly_fig["layout"].template.layout.plot_bgcolor = "white"
self.mpl_x_bounds, self.mpl_y_bounds = mpltools.get_axes_bounds(fig)
margin = go.layout.Margin(
l=int(self.mpl_x_bounds[0] * self.plotly_fig["layout"]["width"]),
Expand Down
10 changes: 10 additions & 0 deletions plotly/matplotlylib/tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,13 @@ def test_multiple_traces_native_legend():
assert plotly_fig.data[0].mode == "lines"
assert plotly_fig.data[1].mode == "markers"
assert plotly_fig.data[2].mode == "lines+markers"



def test_plot_bgcolor_defaults_to_white():
plt.figure()
plt.plot([0, 1], [0, 1])

plotly_fig = tls.mpl_to_plotly(plt.gcf())

assert plotly_fig.layout.template.layout.plot_bgcolor == "white"