Matplotlib is hiring a Research Software Engineering Fellow! See discourse for details. Apply by January 3, 2020
Matplotlib提供了8种指定颜色的方法,
[0, 1]
(例如) (0.1, 0.2, 0.5)
或 (0.1, 0.2, 0.5, 0.3)
)rgba是红色、绿色、蓝色、alpha的缩写;'#0F0F0F'
或 '#0F0F0F0F'
;[0, 1]
包括灰级(例如, '0.5'
;{{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}}
;"blue"
;'xkcd:'
(例如, 'xkcd:sky blue'
;'C'
后跟一个数字,这是默认属性循环的索引 (matplotlib.rcParams['axes.prop_cycle']
);索引发生在艺术家创建时,如果循环不包括颜色,则默认为黑色。{{'tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'}}
这是“tab10”分类调色板中的Tableau颜色(默认颜色循环);有关matplotlib中颜色的详细信息,请参见
matplotlib.colors
应用程序编程接口;import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0.0, 2.0, 201)
s = np.sin(2 * np.pi * t)
# 1) RGB tuple:
fig, ax = plt.subplots(facecolor=(.18, .31, .31))
# 2) hex string:
ax.set_facecolor('#eafff5')
# 3) gray level string:
ax.set_title('Voltage vs. time chart', color='0.7')
# 4) single letter color string
ax.set_xlabel('time (s)', color='c')
# 5) a named color:
ax.set_ylabel('voltage (mV)', color='peachpuff')
# 6) a named xkcd color:
ax.plot(t, s, 'xkcd:crimson')
# 7) Cn notation:
ax.plot(t, .7*s, color='C4', linestyle='--')
# 8) tab notation:
ax.tick_params(labelcolor='tab:orange')
plt.show()
以下函数、方法、类和模块的使用如本例所示: