How to change the text color of font in legend?

前端 未结 5 1972
生来不讨喜
生来不讨喜 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 07:48

    call Legend.get_texts() will get a list of Text object in the legend object:

    import pylab as pl
    pl.plot(randn(100), label="randn")
    l = legend()
    for text in l.get_texts():
        text.set_color("red")
    

提交回复
热议问题