python中的Matplotlib:等同于mpl.rcParams中的fig.set_facecolor?

时间:2019-07-14 14:24:15

标签: python matplotlib tkinter

如果我这样做:

fig = plt.figure()
fig.set_facecolor('#fff1e0')

我更改周围页边距的颜色和轴刻度标签的背景。

我将所有内容都指定为rcParams:

    mpl.rcParams['font.family'] = 'monospace'
    mpl.rcParams['font.size'] = 7
    mpl.rcParams['axes.facecolor'] = 'fff1e0'
    mpl.rcParams['figure.facecolor'] = 'fff1e0'
    mpl.rcParams['figure.edgecolor'] = 'fff1e0'
    mpl.rcParams['axes.edgecolor'] = '6595CC'

    mpl.rcParams['xtick.color'] = '1869B5'
    mpl.rcParams['ytick.color'] = '1869B5'
    mpl.rcParams['grid.color'] = 'EAEFF8'

我想知道对于fig.set_facecolor,在rcParams中哪个等效。

不确定是否相关,但matplotlib是否嵌入Tkinter中。

1 个答案:

答案 0 :(得分:0)

Artist Tutorial指出图中包含所有轴,因此您应该使用mpl.rcParams['figure.facecolor']

docs for Figure支持以下内容:

  

facecolor:默认:rcParams [“ figure.facecolor”]

可以通过注释/取消注释以下相应行来测试这两种方法:

from matplotlib import pyplot as plt
import matplotlib as mpl

mpl.rcParams['figure.facecolor'] = 'maroon'

fig = plt.figure()
##fig.set_facecolor('purple')
plt.plot()
plt.show()
plt.close()

# multiple Axes
fig, axs = plt.subplots(2,2)
##fig.set_facecolor('purple')
for ax,c in zip(axs.flatten(),['red','green','blue','yellow']):
    ax.set_facecolor(c)
plt.show()
plt.close()

mpl.rcdefaults()

Anatomy of a Figure