plt.subplot代码
时间: 2024-02-24 11:50:37 浏览: 90
下面是一个使用plt.subplot()函数创建子图的例子:
```python
import matplotlib.pyplot as plt
# 创建一个2x2的子图,选择第一个子图
plt.subplot(2, 2, 1)
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.title('First Subplot')
# 选择第二个子图
plt.subplot(2, 2, 2)
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'ro')
plt.title('Second Subplot')
# 选择第三个子图
plt.subplot(2, 2, 3)
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'g^')
plt.title('Third Subplot')
# 选择第四个子图
plt.subplot(2, 2, 4)
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'b*')
plt.title('Fourth Subplot')
# 调整子图之间的距离和边距
plt.subplots_adjust(hspace=0.5, wspace=0.5, left=0.125, right=0.9, top=0.9, bottom=0.1)
# 显示图像
plt.show()
```
这个例子创建了一个2x2的子图,分别在四个子图中绘制了不同的点图,并设置了每个子图的标题。最后使用plt.subplots_adjust()函数调整了子图之间的距离和边距。
阅读全文
相关推荐


















