相关疑难解决方法(0)

Matplotlib图facecolor(背景颜色)

有人可以解释为什么设置图形的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.
Run Code Online (Sandbox Code Playgroud)

当我指定使用fig1.set_figheight(11) fig1.set_figwidth(8.5)这些图的高度和宽度时,由命令拾取plt.savefig("trial_fig.png") …

python matplotlib

69
推荐指数
3
解决办法
10万
查看次数

使用matplotlib更改背景*而不使用*框架

鉴于此代码,

from pylab import *
ion()
axes(frameon = 0, aspect = 1, polar = 1)
grid (True)
Run Code Online (Sandbox Code Playgroud)

我得到了包含轴的窗口,我可以在那里绘制我需要的东西.

我想将此窗口的背景从标准灰色更改为另一种颜色.

我不想使用框架.

python matplotlib

4
推荐指数
1
解决办法
6640
查看次数

标签 统计

matplotlib ×2

python ×2