Customizing Matplotlib with style sheets and rcParams#

Tips for customizing the properties and default styles of Matplotlib.

There are three ways to customize Matplotlib:

  1. Setting rcParams at runtime.

  2. Using style sheets.

  3. Changing your matplotlibrc file.

Setting rcParams at runtime takes precedence over style sheets, style sheets take precedence over matplotlibrc files.

Runtime rc settings#

You can dynamically change the default rc (runtime configuration) settings in a python script or interactively from the python shell. All rc settings are stored in a dictionary-like variable called matplotlib.rcParams, which is global to the matplotlib package. See matplotlib.rcParams for a full list of configurable rcParams. rcParams can be modified directly, for example:

from cycler import cycler

import matplotlib.pyplot as plt
import numpy as np

import matplotlib as mpl

mpl.rcParams['lines.linewidth'] = 2
mpl.rcParams['lines.linestyle'] = '--'
data = np.random.randn(50)
plt.plot(data)