Python3绘图库Matplotlib(02)
程序员文章站
2022-03-07 17:17:42
控制颜色 Color Color Name b blue c cyan g green k black m magenta r red w white y yellow Color Color Name b blue c cyan g green k black m magenta r red w ......
控制颜色
Color | Color Name |
b | blue |
c | cyan |
g | green |
k | black |
m | magenta |
r | red |
w | white |
y | yellow |
plt.plot(x1, y1, fmt1, x2, y2, fmt2, ...)
控制线的风格
Style | Style |
- | solid line |
-- | dashed line |
-. | dash-dot line |
: | dotted line |
控制标记样式
. | Point marker |
, | Pixel marker |
o | Circle marker |
v | Triangle down |
^ | Triangle up marker |
< | Triangle left marker |
> | Triangle right marker |
1 | Tripod down marker |
2 | Tripod up marker |
3 | Tripod left marker |
4 | Tripod right marker |
s | Square marker |
p | Pentagon marker |
* | Star marker |
h | Hexagon marker |
H | Rotated hexagon marker |
+ | Plus marker |
x | Cross marker |
D | Diamond marker |
d | Thin diamond marker |
| | Vertical line |
_ | Horizontal line |
用关键字参数进行更好的控制
处理X和Y的ticks标签值
画图的类型
直方图图表 = Histogram charts
Error bar charts
Bar Charts
本小结代码示例
import matplotlib.pyplot as plt import numpy as np y = np.arange(1, 3) plt.plot(y, 'y') plt.plot(y+1, 'm') plt.plot(y+2, 'c') plt.show() import matplotlib.pyplot as plt import numpy as np y = np.arange(1, 3) plt.plot(y, '--', y+1, '-.', y+2, ':') plt.show() import matplotlib.pyplot as plt import numpy as np y = np.arange(1, 3, 0.2) plt.plot(y, 'x', y+0.5, 'o', y+1, 'D', y+1.5, '^', y+2, 's') plt.show() import matplotlib.pyplot as plt import numpy as np y = np.arange(1, 3, 0.3) plt.plot(y, 'cx--', y+1, 'mo:', y+2, 'kp-.') plt.show() import matplotlib.pyplot as plt import numpy as np y = np.arange(1, 3, 0.3) plt.plot(y, color='blue', linestyle='dashdot', linewidth=4, marker='o', markerfacecolor='red', markeredgecolor='black', markeredgewidth=3, markersize=12) plt.show() import matplotlib.pyplot as plt x = [5, 3, 7, 2, 4, 1] plt.plot(x) plt.xticks(range(len(x)), ['a', 'b', 'c', 'd', 'e', 'f']) plt.yticks(range(1, 8, 2)) plt.show() import matplotlib.pyplot as plt import numpy as np y = np.random.randn(1000) plt.hist(y) plt.show() plt.hist(y, 25) plt.show() import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 4, 0.2) y = np.exp(-x) e1 = 0.1 * np.abs(np.random.randn(len(y))) plt.errorbar(x, y, yerr=e1, fmt='.-') plt.show() e2 = 0.1 * np.abs(np.random.randn(len(y))) plt.errorbar(x, y, yerr=e1, xerr=e2, fmt='.-', capsize=0) plt.show() plt.errorbar(x, y, yerr=[e1, e2], fmt='.-') plt.show() import matplotlib.pyplot as plt plt.bar([1, 2, 3], [3, 2, 5]) plt.show() import matplotlib.pyplot as plt import numpy as np data1 = 10*np.random.rand(5) data2 = 10*np.random.rand(5) data3 = 10*np.random.rand(5) e2 = 0.5*np.abs(np.random.randn(len(data2))) locs = np.arange(1, len(data1)+1) width = 0.27 plt.bar(locs+width, data2, yerr=e2, width=width, color='red') plt.bar(locs+2*width, data3, width=width, color='green') plt.show()
知识在于点点滴滴的积累,我会在这个路上Go ahead,
有幸看到我博客的朋友们,若能学到知识,请多多关注以及讨论,让我们共同进步,扬帆起航。
后记:打油诗一首
适度锻炼,量化指标
考量天气,设定目标
科学锻炼,成就体标
高效科研,实现学标
上一篇: selenium登录百度
下一篇: Vue2.0点击切换类名改变样式的方法