Change main plot legend label text

前端 未结 3 668
傲寒
傲寒 2020-12-24 12:16

So far I have been able to label the subplots just fine but I\'m having an issue with the main one.

Here\'s the relevant part of my code:

data_BS_P =         


        
3条回答
  •  一整个雨季
    2020-12-24 12:43

    You need to gain access of the legend() object and use set_text() to change the text values, a simple example:

    plt.plot(range(10), label='Some very long label')
    plt.plot(range(1,11), label='Short label')
    L=plt.legend()
    L.get_texts()[0].set_text('make it short')
    plt.savefig('temp.png')
    

    enter image description here

    In your case, you are changing the first item in the legend, I am quite sure the 0 index in L.get_texts()[0] applies to your problem too.

提交回复
热议问题