Matplot在python中绘制多行

时间:2016-12-06 16:49:06

标签: python matplotlib graph

大家好!我需要在单个图形中使用来自四个数组的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

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

最小工作示例:

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

相关问题