有人能解释为什么下面的代码在设置图形的facecolor时不起作用吗?Matplotlib figure facecolor(背景颜色)
import matplotlib.pyplot as plt
# create figure instance
fig1 = plt.figure(1)
fig1.set_figheight(11)
fig1.set_figwidth(8.5)
rect = fig1.patch
rect.set_facecolor('red') # works with plt.show().
# Does not work with plt.savefig("trial_fig.png")
ax = fig1.add_subplot(1,1,1)
x = 1, 2, 3
y = 1, 4, 9
ax.plot(x, y)
# plt.show() # Will show red face color set above using rect.set_facecolor('red')
plt.savefig("trial_fig.png") # The saved trial_fig.png DOES NOT have the red facecolor.
# plt.savefig("trial_fig.png", facecolor='red') # Here the facecolor is red.
当我指定使用fig1.set_figheight(11)
fig1.set_figwidth(8.5)
这些由命令plt.savefig("trial_fig.png")
拿起该图的高度和宽度。但是,facecolor设置未被拾取。为什么?
感谢您的帮助。
感谢您的解释! – Curious2learn 2011-01-26 19:29:49