How to change the text color of font in legend?

前端 未结 5 1971
生来不讨喜
生来不讨喜 2020-11-30 07:15

Is there a way to change the font color of the legend in a matplotlib plot?

Specially in occasions where the background of the plot is dark, the default black text in

5条回答
  •  鱼传尺愫
    2020-11-30 08:05

    Because plt.setp broadcasts over iterables, you can also modify the text color in one line:

    # Show some cool graphs
    legend = plt.legend()
    plt.setp(legend.get_texts(), color='w')
    

    The last line will apply the colour to all elements in the collection of texts.

提交回复
热议问题