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 the legend is hard or impossible to read.
Use the String fontcolor() Method We can apply the fontcolor() method on any text string, and it returns the <font> HTML element with the color attribute. Users can follow the below syntax to use the fontcolor() method.
seaborn turns the legend frame off by default, if you want to customize how the frame looks, I think you'll need to add frameon=True when you call plt. legend . Show activity on this post. The set_style() method can take a style argument (e.g. 'white' , 'whitegrid' , 'darkgrid' , etc.)
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With