使用plt.show()如何定义背景颜色? [英] Using plt.show() how can I define the background color?

查看:218
本文介绍了使用plt.show()如何定义背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我可视化绘图时,默认背景颜色类似于灰色.我想要一个白色的末端,就像我保存情节时获得的白色末端.

When I visualize a plot, the default background color is something like gray. I want to have a white end, like the one that I obtain when I save the plot.

推荐答案

像任何其他补丁一样,图形本身有一个 set_facecolor() 方法.

Like any other patch, the figure itself has a set_facecolor() method.

fig = plt.figure()
fig.set_facecolor("w")

你也可以直接使用plt.figure()

fig = plt.figure(facecolor="w")

第三个选项是设置相应的rc参数.这可以在脚本的顶部完成

A third option is to set the respective rc Parameter. This can either be done in the top of the script

plt.rcParams["figure.facecolor"] = "w"

或通过更改 matplotlib rc 文件.

请注意,从 matplotlib 2.0 版开始,图形的默认面颜色实际上是白色,因此更新 matplotlib 是第四个可用选项.

Note that from matplotlib version 2.0 on, the default facecolor for figures is actually white, so updating matplotlib is the fourth option available.

这篇关于使用plt.show()如何定义背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆