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

Skip to content

Commit 44f2d83

Browse files
author
Matthew Emmett
committed
Add docstring to rc_context and accept a dictionary too.
1 parent 3954377 commit 44f2d83

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

lib/matplotlib/__init__.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,12 +906,39 @@ def rc_file(fname):
906906

907907

908908
class rc_context(object):
909-
def __init__(self, fname=None):
909+
"""
910+
Return a context manager for managing rc settings.
911+
912+
This allows one to do::
913+
914+
>>> with mpl.rc_context(fname='screen.rc'):
915+
>>> plt.plot(x, a)
916+
>>> with mpl.rc_context(fname='print.rc'):
917+
>>> plt.plot(x, b)
918+
>>> plt.plot(x, c)
919+
920+
The 'a' vs 'x' and 'c' vs 'x' plots would have settings from
921+
'screen.rc', while the 'b' vs 'x' plot would have settings from
922+
'print.rc'.
923+
924+
A dictionary can also be passed to the context manager::
925+
926+
>>> with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
927+
>>> plt.plot(x, a)
928+
929+
The 'rc' dictionary takes precedence over the settings loaded from
930+
'fname'. Passing a dictionary only is also valid.
931+
"""
932+
933+
def __init__(self, rc=None, fname=None):
934+
self.rcdict = rc
910935
self.fname = fname
911936
def __enter__(self):
912937
self._rcparams = rcParams.copy()
913938
if self.fname:
914939
rc_file(self.fname)
940+
if self.rcdict:
941+
rcParams.update(self.rcdict)
915942
def __exit__(self, type, value, tb):
916943
rcParams.update(self._rcparams)
917944

0 commit comments

Comments
 (0)