Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add rc_context and rename rcfile to rc_file.

rc_context is a context manager that optionally accepts a file name:

with mpl.rc_context():
    mpl.rc('lines', linewidth=22)
    ...

or

with mpl.rc_context(fname):
    ...
  • Loading branch information...
commit 395437768adf67967ad8e39f99813d03b97d6faf 1 parent 5bb3c2a
Matthew Emmett authored May 11, 2012

Showing 1 changed file with 13 additions and 2 deletions. Show diff stats Hide diff stats

  1. 15  lib/matplotlib/__init__.py
15  lib/matplotlib/__init__.py
@@ -173,7 +173,6 @@ def byte2str(b): return b
173 173
             __version__numpy__, numpy.__version__))
174 174
 del version
175 175
 
176  
-
177 176
 def is_string_like(obj):
178 177
     if hasattr(obj, 'shape'): return 0
179 178
     try: obj + ''
@@ -898,13 +897,25 @@ def rcdefaults():
898 897
     """
899 898
     rcParams.update(rcParamsDefault)
900 899
 
901  
-def rcfile(fname):
  900
+
  901
+def rc_file(fname):
902 902
     """
903 903
     Update rc params from file.
904 904
     """
905 905
     rcParams.update(rc_params_from_file(fname))
906 906
 
907 907
 
  908
+class rc_context(object):
  909
+    def __init__(self, fname=None):
  910
+        self.fname = fname
  911
+    def __enter__(self):
  912
+        self._rcparams = rcParams.copy()
  913
+        if self.fname:
  914
+            rc_file(self.fname)
  915
+    def __exit__(self, type, value, tb):
  916
+        rcParams.update(self._rcparams)
  917
+
  918
+
908 919
 def rc_file_defaults():
909 920
     """
910 921
     Restore the default rc params from the original matplotlib rc that

0 notes on commit 3954377

Please sign in to comment.
Something went wrong with that request. Please try again.