matplotlib使用

笔者一直云里雾里网上复制着用用,这次打算弄懂闭着眼用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import numpy as np
import matplotlib.pyplot as plt

plt.figure(1)
plt.figure(2)
ax1 = plt.subplot(211)
ax2 = plt.subplot(212)

x = np.linspace(0, 3, 100)
for i in xrange(5):
plt.figure(2)
plt.plot(x, np.exp(i*x/3))
plt.sca(ax1)
plt.plot(x, np.sin(i*x))
plt.sca(ax2)
plt.plot(x, np.cos(i*x))
plt.show()

使用流程1

1
2
3
4
1. plt.figure()
2. plt.imshow(img)
3. plt.plot()
4. plt.show()

使用流程2

1
2
3
4
5
6
1. plt.figure()
2. ax = plt.subplot(211)
3. plt.sca(ax)
4. plt.imshow(img)
5. plt.plot()
6. plt.show()
请作者喝一杯咖啡☕️