plt.subplot

plt.subplot()

在当前图片中绘制一个子图

Add a subplot to the current figure.

此函数参数很多,这里未详细介绍,加一个例子供理解

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

x = np.linspace(1, 10, 20)
y = np.sin(x)

plt.subplot(2,2,1) # 两行两列,位置为1的子图
plt.plot(x,y)

plt.subplot(222) # 两行两列,位置为2的子图
plt.barh(x,y)

plt.subplot(224) # 两行两列,位置为4的子图
plt.bar(x,y)

plt.show()