Set IPython Notebook inline backgrounds not transparent

In IPython Notebook 3, when I use the Inlinematplotlib backend , the png digits in the browser have a transparent background.

How do I set white instead?

Minimal example:

%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2])

Right-click and save the image, the image will have a transparent background, I would like it to be white.

Update Tried to install figure.facecolorin matplotlibrc, but it still displays transparent png:

import matplotlib
print("facecolor before:")
print(matplotlib.rcParams["figure.facecolor"])
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2])
print("facecolor after:")
print(matplotlib.rcParams["figure.facecolor"])

This code gives as output:

facecolor before:
1.0
facecolor after:
(1, 1, 1, 0)
+4
source share
2 answers

Assuming a transparent area is all that surrounds the ax (subplot), you can try the following:

%matplotlib inline
import matplotlib.pyplot as plt
fig, ax = plt.subplots(facecolor='w')
ax.plot([1,2])

, matplotlibrc ( .matplotlib\), :

figure.facecolor = 1

( , , ), facecolor:

fig.savefig('filename.png', facecolor='w', transparent=False)
+5

, facecolor, seaborn.

:

import seaborn as sns

, matplotlib.

0

All Articles