Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text color of font in legend?

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.

like image 756
firefly Avatar asked Sep 20 '13 05:09

firefly


People also ask

How do you change the font color in a script?

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.

How do I change my legend color in Seaborn?

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.)


1 Answers

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") 
like image 94
HYRY Avatar answered Sep 20 '22 15:09

HYRY