matplotlib.pyplot.rc_context

matplotlib.pyplot.rc_context(rc=None, fname=None) [source]

Return a context manager for temporarily changing rcParams.

Parameters:
rcdict

The rcParams to temporarily set.

fnamestr or path-like

A file with Matplotlib rc settings. If both fname and rc are given, settings from rc take precedence.

Examples

Passing explicit values via a dict:

with mpl.rc_context({'interactive': False}):
    fig, ax = plt.subplots()
    ax.plot(range(3), range(3))
    fig.savefig('example.png')
    plt.close(fig)

Loading settings from a file:

with mpl.rc_context(fname='print.rc'):
    plt.plot(x, y)  # uses 'print.rc'

Examples using matplotlib.pyplot.rc_context

© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.3.3/api/_as_gen/matplotlib.pyplot.rc_context.html