File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -912,12 +912,39 @@ def rc_file(fname):
912912
913913
914914class rc_context (object ):
915- def __init__ (self , fname = None ):
915+ """
916+ Return a context manager for managing rc settings.
917+
918+ This allows one to do::
919+
920+ >>> with mpl.rc_context(fname='screen.rc'):
921+ >>> plt.plot(x, a)
922+ >>> with mpl.rc_context(fname='print.rc'):
923+ >>> plt.plot(x, b)
924+ >>> plt.plot(x, c)
925+
926+ The 'a' vs 'x' and 'c' vs 'x' plots would have settings from
927+ 'screen.rc', while the 'b' vs 'x' plot would have settings from
928+ 'print.rc'.
929+
930+ A dictionary can also be passed to the context manager::
931+
932+ >>> with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
933+ >>> plt.plot(x, a)
934+
935+ The 'rc' dictionary takes precedence over the settings loaded from
936+ 'fname'. Passing a dictionary only is also valid.
937+ """
938+
939+ def __init__ (self , rc = None , fname = None ):
940+ self .rcdict = rc
916941 self .fname = fname
917942 def __enter__ (self ):
918943 self ._rcparams = rcParams .copy ()
919944 if self .fname :
920945 rc_file (self .fname )
946+ if self .rcdict :
947+ rcParams .update (self .rcdict )
921948 def __exit__ (self , type , value , tb ):
922949 rcParams .update (self ._rcparams )
923950
You can’t perform that action at this time.
0 commit comments