簡體   English   中英

如何使用Matplotlib更改繪圖的面部顏色

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM