Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add docstring to rc_context and accept a dictionary too.

  • Loading branch information...
commit 0f81dffc05a98fe63e987c2b865a718c53ded7e4 1 parent 2045bdb
@memmett authored committed
Showing with 28 additions and 1 deletion.
  1. +28 −1 lib/matplotlib/__init__.py
View
29 lib/matplotlib/__init__.py
@@ -912,12 +912,39 @@ def rc_file(fname):
class rc_context(object):
- def __init__(self, fname=None):
+ """
+ Return a context manager for managing rc settings.
+
+ This allows one to do::
+
+ >>> with mpl.rc_context(fname='screen.rc'):
+ >>> plt.plot(x, a)
+ >>> with mpl.rc_context(fname='print.rc'):
+ >>> plt.plot(x, b)
+ >>> plt.plot(x, c)
+
+ The 'a' vs 'x' and 'c' vs 'x' plots would have settings from
+ 'screen.rc', while the 'b' vs 'x' plot would have settings from
+ 'print.rc'.
+
+ A dictionary can also be passed to the context manager::
+
+ >>> with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
+ >>> plt.plot(x, a)
+
+ The 'rc' dictionary takes precedence over the settings loaded from
+ 'fname'. Passing a dictionary only is also valid.
+ """
+
+ def __init__(self, rc=None, fname=None):
+ self.rcdict = rc
self.fname = fname
def __enter__(self):
self._rcparams = rcParams.copy()
if self.fname:
rc_file(self.fname)
+ if self.rcdict:
+ rcParams.update(self.rcdict)
def __exit__(self, type, value, tb):
rcParams.update(self._rcparams)
Please sign in to comment.
Something went wrong with that request. Please try again.