其他分享
首页 > 其他分享> > matplotlib 绘制多条折线

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






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

 

标签:plot,plt,color,linestyle,matplotlib,label,折线,marker,绘制
来源: https://blog.csdn.net/qq_40664693/article/details/111672327