python折线图(使用matplotlib,双曲线,图例,中文数据标签)

import numpy as np
import matplotlib.pyplot as plt

if __name__ == "__main__":
    x1=["目标一","目标二","目标四","目标五","目标六","目标三","目标七"]  ##融合
    x2=["目标一","目标二","目标五","目标六","目标四","目标三","目标七"]  ##TOPSIS
    x4=[1,2,3,4,5,6,7]
    y1=np.array([0.3220,0.2000,0.1452,0.1229,0.1159,0.0596,0.0343])  ##融合
    y2 = np.array([0.2076,0.1894,0.1464,0.1426,0.1309,0.1138,0.0694])  ##TOPSIS
    plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
    plt.ylabel(u'纵坐标') 
    plt.xlabel(u'横坐标')   
    A,=plt.plot(x4, y1, "bo-", linewidth=2, markersize=12, label=u"曲线一") 
    B,=plt.plot(x4, y2, "gs-", linewidth=2, markersize=12, label=u"曲线二")
    font1 = {'family': 'SimHei',
             'weight': 'normal',
             'size': 10, }     ##设置图例大小位置
    legend = plt.legend(handles=[A, B], prop=font1)
    for a in range(0,7):  ##向曲线上的点添加数据标签,利用text函数
       plt.text(x4[a],y1[a]-0.025, x1[a], ha='center', va='bottom', fontsize=9,color = "b") #x4[a]表示数据标签横坐标,y1[a]-0.025表示数据标签纵坐标,x1[a]表示数据标签内容
       plt.text(x4[a], y2[a] +0.013, x2[a], ha='center', va='bottom', fontsize=9, color="g")
    #plt.text(x4[2], y2[2] - 0.09, "(0.1,0.25,0.65)", ha='center', va='bottom', fontsize=9, color="g")
    #plt.text(x4[4], y1[4] + 0.07, "(0.1,0.25,0.65)", ha='center', va='bottom', fontsize=9, color="b")

    plt.show()

python折线图(使用matplotlib,双曲线,图例,中文数据标签)_第1张图片

你可能感兴趣的:(python)