@@ -536,15 +536,6 @@ def _get_synced_params(key, value):
536536 if '.' in key :
537537 pass
538538
539- # Special ipython settings
540- # TODO: Put this inside __setitem__?
541- elif key == 'matplotlib' :
542- ipython_matplotlib (value )
543- elif key == 'autosave' :
544- ipython_autosave (value )
545- elif key == 'autoreload' :
546- ipython_autoreload (value )
547-
548539 # Cycler
549540 elif key in ('cycle' , 'rgbcycle' ):
550541 if key == 'rgbcycle' :
@@ -749,9 +740,13 @@ def __init__(self, local=True):
749740 raise err
750741 for key , value in (data or {}).items ():
751742 try :
752- self [ key ] = value
743+ rc_short , rc_long , rc = _get_synced_params ( key , value )
753744 except KeyError :
754745 raise RuntimeError (f'{ file !r} has invalid key { key !r} .' )
746+ else :
747+ rcParamsShort .update (rc_short )
748+ rcParamsLong .update (rc_long )
749+ rcParams .update (rc )
755750
756751 def __enter__ (self ):
757752 """Apply settings from the most recent context block."""
@@ -777,7 +772,10 @@ def __exit__(self, *args):
777772 f'rc context must be initialized with rc.context().' )
778773 * _ , restore = self ._context [- 1 ]
779774 for key , value in restore .items ():
780- self [key ] = value
775+ rc_short , rc_long , rc = _get_synced_params (key , value )
776+ rcParamsShort .update (rc_short )
777+ rcParamsLong .update (rc_long )
778+ rcParams .update (rc )
781779 del self ._context [- 1 ]
782780
783781 def __delitem__ (self , * args ):
@@ -814,8 +812,14 @@ def __setattr__(self, attr, value):
814812
815813 def __setitem__ (self , key , value ):
816814 """Modify an `rcParams \
817- <https://matplotlib.org /users/customizing.html>`__,
815+ <https://matplotlibcorg /users/customizing.html>`__,
818816 :ref:`rcParamsLong`, and :ref:`rcParamsShort` setting(s)."""
817+ if key == 'matplotlib' :
818+ return ipython_matplotlib (value )
819+ elif key == 'autosave' :
820+ return ipython_autosave (value )
821+ elif key == 'autoreload' :
822+ return ipython_autoreload (value )
819823 rc_short , rc_long , rc = _get_synced_params (key , value )
820824 rcParamsShort .update (rc_short )
821825 rcParamsLong .update (rc_long )
@@ -1016,32 +1020,30 @@ def keys(self):
10161020
10171021 def update (self , * args , ** kwargs ):
10181022 """
1019- Update multiple settings at once.
1023+ Update several settings at once with a dictionary and/or
1024+ keyword arguments.
10201025
10211026 Parameters
10221027 ----------
1023- *args : str, dict, or (str, dict)
1024- The first argument can optionally be a "category" string name,
1025- in which case all other setting names passed to this function are
1026- prepended with the string ``cat + ' .'``. For example,
1028+ *args : str, dict, or (str, dict), optional
1029+ A dictionary containing `rc` keys and values. You can also
1030+ pass a "category" name as the first argument, in which case all
1031+ settings are prepended with ``'category .'``. For example,
10271032 ``rc.update('axes', labelsize=20, titlesize=20)`` changes the
10281033 :rcraw:`axes.labelsize` and :rcraw:`axes.titlesize` properties.
1029-
1030- The first or second argument can also be a dictionary of `rc`
1031- names and values.
1032- **kwargs
1033- `rc` names and values passed as keyword arguments. If the
1034+ **kwargs, optional
1035+ `rc` keys and values passed as keyword arguments. If the
10341036 name has dots, simply omit them.
10351037 """
10361038 # Parse args
10371039 kw = {}
10381040 prefix = ''
10391041 if len (args ) > 2 :
10401042 raise ValueError (
1041- 'Accepts 1-2 positional arguments. Use plot.rc.update(kw) '
1042- 'to update a bunch of names, or plot. rc.update(category, kw) '
1043- 'to update subcategories belonging to single category '
1044- 'e.g. axes. Keyword args are added to the kw dict.' )
1043+ f'rc.update() accepts 1-2 arguments, got { len ( args ) } . Usage '
1044+ 'is rc. update(kw), rc.update(category, kw), '
1045+ 'rc. update(**kwargs), or rc.update( category, **kwargs). '
1046+ )
10451047 elif len (args ) == 2 :
10461048 prefix = args [0 ]
10471049 kw = args [1 ]
@@ -1129,7 +1131,8 @@ def ipython_matplotlib(backend=None, fmt=None):
11291131 ibackend = 'qt'
11301132 try :
11311133 ipython .magic ('matplotlib ' + ibackend )
1132- rc .reset ()
1134+ if 'rc' in globals (): # should always be True, but just in case
1135+ rc .reset ()
11331136 except KeyError :
11341137 if backend != 'auto' :
11351138 _warn_proplot (f'{ "%matplotlib " + backend !r} failed.' )
@@ -1214,7 +1217,9 @@ def ipython_autosave(autosave=None):
12141217#: See :ref:`Configuring proplot` for details.
12151218rc = rc_configurator ()
12161219
1217- # Call setup functions
1220+ # Manually call setup functions after rc has been instantiated
1221+ # We cannot call these inside rc.__init__ because ipython_matplotlib may
1222+ # need to reset the configurator to overwrite backend-imposed settings!
12181223ipython_matplotlib ()
12191224ipython_autoreload ()
12201225ipython_autosave ()
0 commit comments