Skip to content

Commit c368e89

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

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

plotly/matplotlylib/renderer.py

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

plotly/matplotlylib/tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import matplotlib
2+
3+
matplotlib.use("Agg")
4+
import matplotlib.pyplot as plt
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import plotly.tools as tls
2+
3+
from . import plt
4+
5+
def test_plot_bgcolor_defaults_to_white():
6+
plt.figure()
7+
plt.plot([0, 1], [0, 1])
8+
9+
plotly_fig = tls.mpl_to_plotly(plt.gcf())
10+
11+
assert plotly_fig.layout.template.layout.plot_bgcolor == "white"

0 commit comments

Comments
 (0)