matplotlib 绘制多条折线

import matplotlib.pyplot as plt

if __name__ == '__main__':

    names = ['0', '1', '2', '3', '4', '5']
    names_y = ['0', '1', '2', '3', '4', '5','6','7']

    x = range(len(names))
    y = range(len(names_y))

    y_1 = [0,0.73, 1.78, 3.13, 4.78, 6.68]
    y_2 = [0,0.68, 1.65, 2.91, 4.46, 6.27]
    y_3 = [0,0.66, 1.56, 2.75, 4.24, 5.99]
    y_4 = [0,0.69, 1.51, 2.55, 3.65, 4.71]
    y_5 = [0,0.61, 1.27, 2.09, 3.10, 4.37]
    y_6 = [0,0.51, 1.21, 2.01, 3.01, 4.31]
    y_7 = [0,0.52, 1.12, 1.95, 2.94, 4.21]
    plt.xlim(0,5)
    plt.ylim(0,7)

    plt.plot(x, y_1, color='red', marker='*', linestyle='-', label='A')
    plt.plot(x, y_2, color='blue', marker='*', linestyle='-', label='B')
    plt.plot(x, y_3, color='green', marker='*', linestyle='-', label='C')
    plt.plot(x, y_4, color='red', marker='*', linestyle='-', label='D')
    plt.plot(x, y_5, color='dodgerblue', marker='*', linestyle='-', label='E')
    plt.plot(x, y_6, color='cyan', marker='*', linestyle='-', label='F')
    plt.plot(x, y_7, color='magenta', marker='*', linestyle='-', label='G')
    plt.legend()  # 显示图例
    #plt.xticks(x, names, rotation=45)
    #plt.yticks(y, names_y, rotation=45)

    plt.ylabel("RMSE error(m)")  # 设置Y轴标签
    plt.xlabel("prediction Horizon(s)")  # 设置X轴标签
    plt.savefig("RMSE")#保存图片
    plt.show()






该代码绘制出来的多折线对比图如下图所示(结果展示):

 

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值