Configuring Matplotlib
We have learned to tweak a few major elements in a Matplotlib plot. When we recurrently generate figures of similar style, it would be nice to have a way to store and apply the persistent global settings. Matplotlib offers a few options for configuration.
Configuring within Python code
To keep settings throughout the current session, we can execute matplotlib.rcParams
to override configuration file settings.
For instance, we can set the font size of all text in plots to 18 with the following:
matplotlib.rcParams['font.size'] = 18
Alternatively we can call the matplotlib.rc()
function. As matplotlib.rc()
just changes one property, to change multiple settings, we can use the function matplotlib.rcParams.update()
, and pass parameters in the form of a dictionary of key-value pairs:
matplotlib.rcParams.update({'font.size': 18, 'font.family': 'serif'})
Reverting to default settings
To revert to default settings, you can call matplotlib.rcdefaults()
or matplotlib.style.use('default...