Matplot用python绘制多条直线

2024-10-03 13:22:05 发布

您现在位置:Python中文网/ 问答频道 /正文

所有人!我需要使用matplotlib(不一定)从单个图形中的四个数组绘制多条线。目前我的代码是

plt.plot(PTime,PReactions,NYTime,NYReactions,LTime,LReactions,SFTime,SFReactions)
plt.show()      

PTime和PReactions是数组的名称,依此类推。
这是上述代码的输出:

This is the output of the above code

但我不想要这种类型的图表。我要多行表示不同的数组(不同的数据)。
我想要类似的结果:

I want results something similar to this


Tags: 代码图形plotmatplotlib绘制plt数组所有人
2条回答

最小工作示例:

import matplotlib.pyplot as plt
import numpy as np

a=np.linspace(0, 1, 10)
b=np.linspace(0, 2, 10)
c=np.linspace(0, 3, 10)
d=np.linspace(0, 4, 10)

plt.plot(b,a)
plt.plot(c,a)
plt.plot(d,a)

plt.show()

给你:

enter image description here

您的数据以错误的顺序显示。它必须是X, Y

plt.plot(PReactions, PTime)
plt.plot(NYReactions, NYTime)
plt.plot(LReactions, LTime)
plt.plot(SFReactions, SFTime)
plt.show()

相关问题 更多 >