1 2
| pip install matplotlib import matplotlib.pyplot as plt
|
1 2
| matplotlib.rcParams['font.sans-serif'] = ['SimHei'] matplotlib.rcParams['axes.unicode_minus'] = False
|
基本方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| title() xlabel() ylabel() xticks(x, ticks, rotation) yticks() ylim() plot() show() legend() text(x, y, text) figure(name, figsize=(w, h), dpi=n) savefig() subplot() fig_, ax_ = plt.subplots(neows, ncols)
fill_between(x, y1, y2, color='')
|
1 2 3 4 5 6 7 8 9
| fontsize label loc
plt.style.available plt.style.use('指定风格')
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| plt.plot(x, y, ...) plt.show()
- -- -. : , o v ^ + 1 2 3 a b c * h ...
b g r c m y k w
plt.plot(x, y, '-r')
|
1 2 3 4 5
| plt.scatter() plt.plot( x, y, 'o')
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| plt.bar() plt.barh()
x=range(5) y=[1, -3, 4, -5, 6] v_bar = plt.bar(x, y, color='lightblue') for bar, height in zip(v_bar, y): if height < 0: bar.set(color='lightgreen', linewidth='3')
bar.get_width() bar.get_y() bar.get_height()
plt.bar( , , yerr=variance_)
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| plt.contourf()
X, Y = np.meshgrid(x, y)
from mpl_toolkits.mplot3d import Axes3D figure=plt.figure() ax=Axes3D(figure) ax.plot_surface(X,Y,Z)
|
参考学习
https://www.runoob.com/matplotlib/matplotlib-tutorial.html