Python中一个图形中的多个图

user3183660:

我是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()

但是我得到的是一个单独的图,一个图一个图。有人可以帮我弄清楚我们的代码有什么问题吗?为什么不能产生多条线图?非常感谢!

游戏Brainiac:

这很简单:

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")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章