在Python中,`subplots`通常指的是在图形用户界面(GUI)中创建子图的功能。`subplots`函数允许你在一个窗口或图形中创建多个子图,每个子图可以用于绘制不同的数据或图表。
```python
import matplotlib.pyplot as plt
创建一个2行1列的子图布局
fig, axs = plt.subplots(2, 1)
在第一个子图上绘制数据
x1 = [0, 1, 2, 3, 4]
y1 = [2 * x * math.exp(-5 * x) for x in x1]
axs.plot(x1, y1, 'b-')
axs.set_xlabel('x')
axs.set_ylabel('f(x)')
在第二个子图上绘制数据
x2 = [-4, -3, -2, -1, 0]
y2 = [5 * math.sin(5 * math.pi * x) for x in x2]
axs.plot(x2, y2, 'r-')
axs.set_xlabel('x')
axs.set_ylabel('g(x)')
显示图形
plt.show()
在这个例子中,`plt.subplots(2, 1)`创建了一个2行1列的子图布局,`axs`是一个包含两个子图轴对象的数组。然后,我们分别在这两个子图上绘制了数据,并设置了坐标轴标签。最后,使用`plt.show()`显示整个图形。