[英]How to change the face color of a plot using 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')
嗯,你可以试试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')
这是你想要的吗?
#!/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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.