File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -906,12 +906,39 @@ def rc_file(fname):
906906
907907
908908class rc_context (object ):
909- def __init__ (self , fname = None ):
909+ """
910+ Return a context manager for managing rc settings.
911+
912+ This allows one to do::
913+
914+ >>> with mpl.rc_context(fname='screen.rc'):
915+ >>> plt.plot(x, a)
916+ >>> with mpl.rc_context(fname='print.rc'):
917+ >>> plt.plot(x, b)
918+ >>> plt.plot(x, c)
919+
920+ The 'a' vs 'x' and 'c' vs 'x' plots would have settings from
921+ 'screen.rc', while the 'b' vs 'x' plot would have settings from
922+ 'print.rc'.
923+
924+ A dictionary can also be passed to the context manager::
925+
926+ >>> with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
927+ >>> plt.plot(x, a)
928+
929+ The 'rc' dictionary takes precedence over the settings loaded from
930+ 'fname'. Passing a dictionary only is also valid.
931+ """
932+
933+ def __init__ (self , rc = None , fname = None ):
934+ self .rcdict = rc
910935 self .fname = fname
911936 def __enter__ (self ):
912937 self ._rcparams = rcParams .copy ()
913938 if self .fname :
914939 rc_file (self .fname )
940+ if self .rcdict :
941+ rcParams .update (self .rcdict )
915942 def __exit__ (self , type , value , tb ):
916943 rcParams .update (self ._rcparams )
917944
You can’t perform that action at this time.
0 commit comments