Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2045bdb

Browse files
Matthew Emmettmemmett
Matthew Emmett
authored andcommitted
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): ...
1 parent ceb66d4 commit 2045bdb

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/matplotlib/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ def byte2str(b): return b
178178
__version__numpy__, numpy.__version__))
179179
del version
180180

181-
182181
def is_string_like(obj):
183182
if hasattr(obj, 'shape'): return 0
184183
try: obj + ''
@@ -904,13 +903,25 @@ def rcdefaults():
904903
"""
905904
rcParams.update(rcParamsDefault)
906905

907-
def rcfile(fname):
906+
907+
def rc_file(fname):
908908
"""
909909
Update rc params from file.
910910
"""
911911
rcParams.update(rc_params_from_file(fname))
912912

913913

914+
class rc_context(object):
915+
def __init__(self, fname=None):
916+
self.fname = fname
917+
def __enter__(self):
918+
self._rcparams = rcParams.copy()
919+
if self.fname:
920+
rc_file(self.fname)
921+
def __exit__(self, type, value, tb):
922+
rcParams.update(self._rcparams)
923+
924+
914925
def rc_file_defaults():
915926
"""
916927
Restore the default rc params from the original matplotlib rc that

0 commit comments

Comments
 (0)