Permalink
Browse files

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...
1 parent 5bb3c2a commit 395437768adf67967ad8e39f99813d03b97d6faf @memmett committed May 11, 2012
Showing with 13 additions and 2 deletions.
  1. +13 −2 lib/matplotlib/__init__.py
View
@@ -173,7 +173,6 @@ def byte2str(b): return b
__version__numpy__, numpy.__version__))
del version
-
def is_string_like(obj):
if hasattr(obj, 'shape'): return 0
try: obj + ''
@@ -898,13 +897,25 @@ def rcdefaults():
"""
rcParams.update(rcParamsDefault)
-def rcfile(fname):
+
+def rc_file(fname):
"""
Update rc params from file.
"""
rcParams.update(rc_params_from_file(fname))
+class rc_context(object):
+ def __init__(self, fname=None):
+ self.fname = fname
+ def __enter__(self):
+ self._rcparams = rcParams.copy()
+ if self.fname:
+ rc_file(self.fname)
+ def __exit__(self, type, value, tb):
+ rcParams.update(self._rcparams)
+
+
def rc_file_defaults():
"""
Restore the default rc params from the original matplotlib rc that

0 comments on commit 3954377

Please sign in to comment.