rcParams (Matplotlib)

rcParams is Matplotlib's global dictionary of default settings, controlling things like default figure size, font size, line width, and color cycle. Changing it alters the defaults for every plot you make afterward.

Matplotlib

Every default Matplotlib uses — plt.rcParams['lines.linewidth'], plt.rcParams['figure.figsize'], plt.rcParams['font.size'] — lives in this dictionary. Setting a value changes the default for all subsequent plots in the session, so you configure look-and-feel once rather than on every call.

It is the mechanism behind style sheets: applying a style simply writes a batch of values into rcParams. You can edit individual entries for fine control, set many at once with plt.rc(), or reset everything to the factory defaults with plt.rcdefaults().

For persistent, project-wide defaults, the same keys can be placed in a matplotlibrc configuration file. To change settings only for a block of code, prefer the temporary context manager (plt.rc_context) so you don't leave global state altered.

Syntax

plt.rcParams['figure.figsize'] = (8, 5)  |  plt.rcParams['font.size'] = 12

Examples

Python — The default line width before any change.

import matplotlib.pyplot as plt
print(plt.rcParams["lines.linewidth"])

Output:

1.5

Learn it in a lesson

See also

Back to the Dictionary