如何使用Matplotlib更改绘图的面部颜色

时间:2011-03-03 14:12:28

标签: python matplotlib

我刚刚开始使用Matplotlib,我正试图改变情节的脸颜色...

如果我创建这样的数字:

 plt.figure(num=None, figsize=(5, 10), dpi=80, facecolor='y', edgecolor='k')

只有图中的边框变为黄色...我想要的是白色的边框和黄色的情节..

编辑:

来自我当前代码的剪辑:

plt.figure(num=None, figsize=(5, 10), dpi=80, facecolor='y', edgecolor='k')  

ax = plt.gca()

ax.plot(x, y, color = 'g')

enter image description here

2 个答案:

答案 0 :(得分:6)

嗯,你可以试试set_axis_bgcolor。另外,不要使用gca,试试这个,它更干净:

fig = plt.figure(num=None, figsize=(5, 10), dpi=80, facecolor='y', edgecolor='k')
ax = fig.add_subplot(111)
ax.set_axis_bgcolor("y")
ax.plot(x, y, color = 'g')

答案 1 :(得分:6)

this你想要的是什么吗?

enter image description here

#!/usr/bin/env python
"""
matplotlib gives you 4 ways to specify colors,

    1) as a single letter string, ala MATLAB

    2) as an html style hex string or html color name

    3) as an R,G,B tuple, where R,G,B, range from 0-1

    4) as a string representing a floating point number
       from 0 to 1, corresponding to shades of gray.

See help(colors) for more info.
"""
from pylab import *

subplot(111, axisbg='darkslategray')
#subplot(111, axisbg='#ababab')
t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
plot(t, s, 'y')
xlabel('time (s)', color='r')
ylabel('voltage (mV)', color='0.5') # grayscale color
title('About as silly as it gets, folks', color='#afeeee')
show()