简明matplotlib API入门

这里看一个简单的例子:

1
2
3
4
5
6
import numpy as np
import matplotlib.pyplot as plt
data = np.arange(10)
print(data) ==>
[0 1 2 3 4 5 6 7 8 9]
print(plt.plot(data)) #输出图片见下:

图片与子图

可以用函数add_subplot来创建一个或多个子图

1
2
3
4
fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)

输出如下:

Author: YihangBao
Link: https://roarboil.github.io/2019/09/27/matintro/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.