Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change the default font color for all text in matplotlib?

This only changed it for chart titles, but left axis titles the default color:

import matplotlib as mpl
mpl.rcParams['text.color'] = 'blue'
like image 910
Max Ghenis Avatar asked Feb 24 '18 00:02

Max Ghenis


People also ask

How do I change the font color in matplotlib?

Plot x and y using plot() method, where color of line is red and label is "y=exp(x)". To place the legend, use legend() method with location of the legend and store the returned value to set the color of the text. To set the color of the text, use set_color() method with green color.

What is the default color in matplotlib?

MatPlotLib with Python The default color of a scatter point is blue. To get the default blue color of matplotlib scatter point, we can annotate them using annotate() method.

What is the default font for matplotlib?

The default font has changed from "Bitstream Vera Sans" to "DejaVu Sans".


Video Answer


2 Answers

You can set each text property separately, e.g.:

COLOR = 'blue'
mpl.rcParams['text.color'] = COLOR
mpl.rcParams['axes.labelcolor'] = COLOR
mpl.rcParams['xtick.color'] = COLOR
mpl.rcParams['ytick.color'] = COLOR

The full list of params is at https://matplotlib.org/users/customizing.html.

like image 162
Max Ghenis Avatar answered Oct 10 '22 12:10

Max Ghenis


To set the label color in the rcParams as well use

text.color: blue
axes.labelcolor: blue

or, from within the script

mpl.rcParams.update({'text.color' : "blue",
                     'axes.labelcolor' : "blue"})
like image 28
ImportanceOfBeingErnest Avatar answered Oct 10 '22 14:10

ImportanceOfBeingErnest