在 IPython Notebook 3 中,当我使用Inline
matplotlib后端,浏览器中的png图形具有透明背景。
我该如何将其设置为白色?
最小的例子:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2])
右键单击并保存图像,图像具有透明背景,我希望它是白色的。
Update尝试设置figure.facecolor
in matplotlibrc
但它仍然显示一个透明的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"])
此代码给出输出:
facecolor before:
1.0
facecolor after:
(1, 1, 1, 0)
假设透明区域是斧头周围的所有区域(子图),您可以尝试以下操作:
%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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)