请问有人能解释一下为什么在设置图形 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设置没有被捕获。为什么?
感谢您的帮助。
facecolor
现在会触发一个警告:MatplotlibDeprecationWarning: savefig()得到了意外的关键字参数"fc",自3.3版本起不再支持,并将在3.6版本中成为错误。
- C-3PO