我是 python 新手,正在尝试使用 matplotlib 在同一个图中绘制多条线。
我的 Y 轴的值存储在字典中,我在以下代码中在 X 轴中制作相应的值
我的代码是这样的:
for i in range(len(ID)):
AxisY= PlotPoints[ID[i]]
if len(AxisY)> 5:
AxisX= [len(AxisY)]
for i in range(1,len(AxisY)):
AxisX.append(AxisX[i-1]-1)
plt.plot(AxisX,AxisY)
plt.xlabel('Lead Time (in days)')
plt.ylabel('Proportation of Events Scheduled')
ax = plt.gca()
ax.invert_xaxis()
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
plt.show()
但我得到了一个又一个具有单一情节的单独数字。有人能帮我找出我的代码有什么问题吗?为什么我无法生成多线绘图?多谢!
这非常简单:
import matplotlib.pyplot as plt
plt.plot(<X AXIS VALUES HERE>, <Y AXIS VALUES HERE>, 'line type', label='label here')
plt.plot(<X AXIS VALUES HERE>, <Y AXIS VALUES HERE>, 'line type', label='label here')
plt.legend(loc='best')
plt.show()
可以继续添加plt.plot
想要多少次都可以。至于line type
,您需要首先指定颜色。所以对于蓝色来说,b
。对于普通线路来说是-
。一个例子是:
plt.plot(total_lengths, sort_times_heap, 'b-', label="Heap")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)