【发布时间】:2015-06-16 17:57:01
【问题描述】:
在 IPython Notebook 3 中,当我使用 Inline matplotlib 后端时,浏览器中的 png 图形具有透明背景。
如何将其设置为白色?
小例子:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2])
右键保存图片,图片有透明背景,我希望它是白色的。
更新
尝试在matplotlibrc 中设置figure.facecolor,但它仍然显示透明的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 notebook -
感谢@tcaswell,不知道这个!但是我真的更喜欢使用
inline后端。它看起来更轻巧。 -
是的,但它不是交互式的(这至少是 mpl 功能的一半)。
-
以及硬编码到 IPython 中的透明背景添加到 github.com/ipython/ipython/pull/6064 新问题报告 github.com/ipython/ipython/issues/7964
-
感谢@tcaswell 找到这个
标签: python matplotlib ipython-notebook