Is it possible to add a string as a legend item in matplotlib

前端 未结 2 1205
夕颜
夕颜 2020-12-01 07:54

I am producing some plots in matplotlib and would like to add explanatory text for some of the data. I want to have a string inside my legend as a separate legend item above

2条回答
  •  無奈伤痛
    2020-12-01 08:03

    Alternative solution, kind of dirty but pretty quick.

    import pylab as plt
    
    X = range(50)
    Y = range(50)
    plt.plot(X, Y, label="Very straight line")
    
    # Create empty plot with blank marker containing the extra label
    plt.plot([], [], ' ', label="Extra label on the legend")
    
    plt.legend()
    plt.show()
    

提交回复
热议问题