matplotlib.pyplot.rc_context#
- matplotlib.pyplot.rc_context(rc=None,fname=None)[source]#
Return a context manager for temporarily changing rcParams.
The
rcParams["backend"]
will not be reset by the context manager.rcParams changed both through the context manager invocation andin the body of the context will be reset on context exit.
- Parameters:
- rcdict
The rcParams to temporarily set.
- fnamestr or path-like
A file with Matplotlib rc settings. If bothfname andrc are given,settings fromrc take precedence.
See also
Notes
Note
This is equivalent to
matplotlib.rc_context
.Examples
Passing explicit values via a dict:
withmpl.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:
withmpl.rc_context(fname='print.rc'):plt.plot(x,y)# uses 'print.rc'
Setting in the context body:
withmpl.rc_context():# will be resetmpl.rcParams['lines.linewidth']=5plt.plot(x,y)
Examples usingmatplotlib.pyplot.rc_context
#
On this page