File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -912,12 +912,39 @@ def rc_file(fname):
912
912
913
913
914
914
class 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
916
941
self .fname = fname
917
942
def __enter__ (self ):
918
943
self ._rcparams = rcParams .copy ()
919
944
if self .fname :
920
945
rc_file (self .fname )
946
+ if self .rcdict :
947
+ rcParams .update (self .rcdict )
921
948
def __exit__ (self , type , value , tb ):
922
949
rcParams .update (self ._rcparams )
923
950
You can’t perform that action at this time.
0 commit comments