@@ -1411,16 +1411,17 @@ def context(self, *args, mode=0, file=None, **kwargs):
1411
1411
>>> ax.format(ticklen=5, metalinewidth=2)
1412
1412
"""
1413
1413
# Add input dictionaries
1414
+ # WARNING: Critical to fully apply
1414
1415
for arg in args :
1415
1416
if not isinstance (arg , dict ):
1416
- raise ValueError ('Non-dictionary argument {arg!r}.' )
1417
+ raise ValueError (f 'Non-dictionary argument { arg !r} .' )
1417
1418
kwargs .update (arg )
1418
1419
1419
1420
# Add settings from file
1420
1421
if file is not None :
1421
- kw_proplot , kw_matplotlib = self ._load_file (file )
1422
- kwargs . update ( kw_proplot )
1423
- kwargs .update (kw_matplotlib )
1422
+ kw = self ._load_file (file )
1423
+ kw = { key : value for key , value in kw . items () if key not in kwargs }
1424
+ kwargs .update (kw )
1424
1425
1425
1426
# Activate context object
1426
1427
if mode not in range (3 ):
@@ -1569,10 +1570,11 @@ def _load_file(self, path):
1569
1570
"""
1570
1571
Return dictionaries of proplot and matplotlib settings loaded from the file.
1571
1572
"""
1572
- added = set ()
1573
+ # WARNING: Critical to not yet apply _get_item_dicts() syncing or else we
1574
+ # can overwrite input settings (e.g. label.size followed by font.size).
1573
1575
path = os .path .expanduser (path )
1574
- kw_proplot = {}
1575
- kw_matplotlib = {}
1576
+ added = set ()
1577
+ rcdict = {}
1576
1578
with open (path , 'r' ) as fh :
1577
1579
for idx , line in enumerate (fh ):
1578
1580
# Strip comments
@@ -1587,33 +1589,34 @@ def _load_file(self, path):
1587
1589
warnings ._warn_proplot (f'Illegal { message } :\n { line } "' )
1588
1590
continue
1589
1591
# Detect duplicates
1590
- key , val = map (str .strip , pair )
1592
+ key , value = map (str .strip , pair )
1591
1593
if key in added :
1592
1594
warnings ._warn_proplot (f'Duplicate rc key { key !r} on { message } .' )
1593
1595
added .add (key )
1594
1596
# Get child dictionaries. Careful to have informative messages
1595
1597
with warnings .catch_warnings ():
1596
1598
warnings .simplefilter ('error' , warnings .ProplotWarning )
1597
1599
try :
1598
- ikw_proplot , ikw_matplotlib = self ._get_item_dicts (key , val )
1600
+ key , value = self ._validate_key (key , value )
1601
+ value = self ._validate_value (key , value )
1599
1602
except KeyError :
1600
1603
warnings .simplefilter ('default' , warnings .ProplotWarning )
1601
1604
warnings ._warn_proplot (f'Invalid rc key { key !r} on { message } .' )
1602
1605
continue
1603
1606
except ValueError as err :
1604
1607
warnings .simplefilter ('default' , warnings .ProplotWarning )
1605
- warnings ._warn_proplot (f'Invalid rc val { val !r} for key { key !r} on { message } : { err } ' ) # noqa: E501
1608
+ warnings ._warn_proplot (f'Invalid rc value { value !r} for key { key !r} on { message } : { err } ' ) # noqa: E501
1606
1609
continue
1607
1610
except warnings .ProplotWarning as err :
1608
1611
warnings .simplefilter ('default' , warnings .ProplotWarning )
1609
1612
warnings ._warn_proplot (f'Outdated rc key { key !r} on { message } : { err } ' ) # noqa: E501
1610
1613
warnings .simplefilter ('ignore' , warnings .ProplotWarning )
1611
- ikw_proplot , ikw_matplotlib = self ._get_item_dicts (key , val )
1614
+ key , value = self ._validate_key (key , value )
1615
+ value = self ._validate_value (key , value )
1612
1616
# Update the settings
1613
- kw_proplot .update (ikw_proplot )
1614
- kw_matplotlib .update (ikw_matplotlib )
1617
+ rcdict [key ] = value
1615
1618
1616
- return kw_proplot , kw_matplotlib
1619
+ return rcdict
1617
1620
1618
1621
def load (self , path ):
1619
1622
"""
@@ -1628,9 +1631,9 @@ def load(self, path):
1628
1631
--------
1629
1632
Configurator.save
1630
1633
"""
1631
- kw_proplot , kw_matplotlib = self ._load_file (path )
1632
- rc_proplot . update ( kw_proplot )
1633
- rc_matplotlib . update ( kw_matplotlib )
1634
+ rcdict = self ._load_file (path )
1635
+ for key , value in rcdict . items ():
1636
+ self . __setitem__ ( key , value )
1634
1637
1635
1638
@staticmethod
1636
1639
def _save_rst (path ):
@@ -1688,10 +1691,12 @@ def save(self, path=None, user=True, comment=None, backup=True, description=Fals
1688
1691
backup : bool, default: True
1689
1692
Whether to "backup" an existing file by renaming with the suffix ``.bak``
1690
1693
or overwrite an existing file.
1691
- comment : bool, default: `user`
1692
- Whether to comment out the default settings.
1694
+ comment : bool, optional
1695
+ Whether to comment out the default settings. If not passed
1696
+ this takes the same value as `user`.
1693
1697
description : bool, default: False
1694
- Whether to include descriptions of each setting as comments.
1698
+ Whether to include descriptions of each setting (as seen in the
1699
+ :ref:`user guide table <ug_rctable>`) as comments.
1695
1700
1696
1701
See also
1697
1702
--------
0 commit comments