Black background behind a figure's labels and ticks, only after saving figure but not in Python Interactive view (VS Code with Jupyter functionality)?

北城余情 提交于 2019-12-13 01:47:00

问题


I have a strange problem where if I save a figure, its labels and ticks will have a black background, see this example:

plt.savefig("asdsadsad.png")

I'm not even including any code here because this happens on the simplest plotting, even with code that I made earlier with a different computer that never had this problem. I'm using VS Code with Jupyter functionality and the figures look normal in the Python Interactive view, but have the black border when saved.

Any ideas what could cause this strange problem?


回答1:


plt.savefig will overwrite your settings that you plotted with. That's why the saved image might look different from what you have plotted in Python. To define the background color of your figure, you need to define the facecolor parameter.

plt.savefig('asdsadsad.png', facecolor='w')

Your default facecolor may be set to black in your rcParams



来源:https://stackoverflow.com/questions/53727761/black-background-behind-a-figures-labels-and-ticks-only-after-saving-figure-bu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!