Skip to content

Commit fcfb7d0

Browse files
committedJan 23, 2017
5.1
1 parent a73cd84 commit fcfb7d0

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
 

‎5.1.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# 指定颜色
2+
3+
> 原文:[Specifying Colors](http://matplotlib.org/users/colors.html)
4+
5+
> 译者:[飞龙](https://github.com/)
6+
7+
> 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
8+
9+
在 matplotlib 的几乎所有地方,用户都可以指定颜色,它可以以如下形式提供:
10+
11+
+ RGB 或者 RGBA 浮点值元组,`[0, 1]`之间,例如`(0.1, 0.2, 0.5)`或者`(0.1, 0.2, 0.5, 0.3)`
12+
13+
+ RGB 或者 RGBA 十六进制字符串,例如`#0F0F0F`或者`#0F0F0F0F`
14+
15+
+ `[0, 1]`之间的浮点值的字符串表示,用于表示灰度,例如`0.5`
16+
17+
+ `{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}`之一。
18+
19+
+ X11/CSS4 颜色名称。
20+
21+
+ [XKCD 颜色](https://xkcd.com/color/rgb/)之一,以`'xkcd:'`为前缀,例如`'xkcd:sky blue'`
22+
23+
+ `{'C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'}`之一。
24+
25+
+ `{'tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'}`之一。这是 T10 调色板的 Tableau 颜色(默认的色相环)。
26+
27+
所有颜色字符串都是大小写敏感的。
28+
29+
## `CN`颜色选择
30+
31+
颜色可以通由匹配正则表达式`C[0-9]`的字符串来指定。 这可以在任何当前接受颜色的地方传递,并且可以在`matplotlib.Axes.plot``format-string`中用作“单个字符颜色”。
32+
33+
单个数字是默认属性环的索引(`matplotlib.rcParams['axes.prop_cycle']`)。 如果属性环不包括`'color'`,则返回黑色。 在创建 Artist 时会对颜色求值。 例如:
34+
35+
```py
36+
import numpy as np
37+
import matplotlib.pyplot as plt
38+
import matplotlib as mpl
39+
th = np.linspace(0, 2*np.pi, 128)
40+
41+
def demo(sty):
42+
mpl.style.use(sty)
43+
fig, ax = plt.subplots(figsize=(3, 3))
44+
45+
ax.set_title('style: {!r}'.format(sty), color='C0')
46+
47+
ax.plot(th, np.cos(th), 'C1', label='C1')
48+
ax.plot(th, np.sin(th), 'C2', label='C2')
49+
ax.legend()
50+
51+
demo('default')
52+
```
53+
54+
![](http://matplotlib.org/_images/colors-1_00.png)
55+
56+
![](http://matplotlib.org/_images/colors-1_01.png)

‎5.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 颜色

0 commit comments

Comments
 (0)