python画一个包含3个子图的图,3个子图按列排列,并分别设置坐标轴标题,坐标轴范围,给图加一个总标题
时间: 2024-05-03 21:20:06 浏览: 12
好的,这是一个比较简单的问题,以下是代码示例:
```python
import matplotlib.pyplot as plt
# 创建一个包含3个子图的图,3个子图按列排列
fig, ax = plt.subplots(3, 1)
# 设置第一个子图
ax[0].plot([1, 2, 3], [4, 5, 6])
ax[0].set_title('Subplot 1')
ax[0].set_xlim(0, 4)
ax[0].set_ylim(0, 7)
ax[0].set_xlabel('X Axis Label')
ax[0].set_ylabel('Y Axis Label')
# 设置第二个子图
ax[1].scatter([1, 2, 3], [4, 5, 6])
ax[1].set_title('Subplot 2')
ax[1].set_xlim(0, 4)
ax[1].set_ylim(0, 7)
ax[1].set_xlabel('X Axis Label')
ax[1].set_ylabel('Y Axis Label')
# 设置第三个子图
ax[2].bar([1, 2, 3], [4, 5, 6])
ax[2].set_title('Subplot 3')
ax[2].set_xlim(0, 4)
ax[2].set_ylim(0, 7)
ax[2].set_xlabel('X Axis Label')
ax[2].set_ylabel('Y Axis Label')
# 给图加一个总标题
fig.suptitle('Main Title')
# 展示图形
plt.show()
```
希望能够帮到您!
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)