pythonn画四个折线图,在同一个界面,纵向排布
时间: 2024-03-06 14:51:51 浏览: 20
好的,您可以使用 Python 的数据可视化库 Matplotlib 来实现这个需求。以下是一个简单的示例代码,可以画出四个折线图并纵向排布:
```python
import matplotlib.pyplot as plt
import numpy as np
# 生成数据
x = np.arange(1, 11)
y1 = np.random.randint(1, 10, size=10)
y2 = np.random.randint(1, 10, size=10)
y3 = np.random.randint(1, 10, size=10)
y4 = np.random.randint(1, 10, size=10)
# 创建画布和子图
fig, axs = plt.subplots(4, 1, figsize=(6, 8))
# 画第一个折线图
axs[0].plot(x, y1, '-o', color='red')
axs[0].set_title('Line 1')
# 画第二个折线图
axs[1].plot(x, y2, '-o', color='blue')
axs[1].set_title('Line 2')
# 画第三个折线图
axs[2].plot(x, y3, '-o', color='green')
axs[2].set_title('Line 3')
# 画第四个折线图
axs[3].plot(x, y4, '-o', color='orange')
axs[3].set_title('Line 4')
# 调整子图之间的间距
plt.subplots_adjust(hspace=0.5)
# 显示图形
plt.show()
```
您可以根据实际需求修改数据和参数。希望对您有所帮助!