Skip to content

Commit d862395

Browse files
committed
Cleanup rcsetup and fix issues with rc.changed
Previously unchanged settings were falsely detected as changed because we were comparing against an unstandardized _rc_matplotlib_default dictionary. Now we wrap that dictionary with RcParams. This also adds __repr__ and __str__ for the proplot _RcParams dictionary so that the appearance of pplt.rc_matplotlib and pplt.rc_proplot is the same.
1 parent 7ceefba commit d862395

1 file changed

Lines changed: 31 additions & 22 deletions

File tree

proplot/internals/rcsetup.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ def __init__(self, source, validate):
412412
for key, value in source.items():
413413
self.__setitem__(key, value) # trigger validation
414414

415+
def __repr__(self):
416+
return RcParams.__repr__(self)
417+
418+
def __str__(self):
419+
return RcParams.__repr__(self)
420+
415421
def __len__(self):
416422
return dict.__len__(self)
417423

@@ -539,7 +545,7 @@ def copy(self):
539545
'axes.ymargin': MARGIN,
540546
'errorbar.capsize': 3.0,
541547
'figure.autolayout': False,
542-
'figure.figsize': (4, 4), # for interactife backends
548+
'figure.figsize': (4.0, 4.0), # for interactife backends
543549
'figure.dpi': 100,
544550
'figure.facecolor': '#f4f4f4', # similar to MATLAB interface
545551
'figure.titlesize': LARGESIZE,
@@ -1823,10 +1829,10 @@ def copy(self):
18231829
'tick.labelsize': ('xtick.labelsize', 'ytick.labelsize'),
18241830
}
18251831

1826-
# Symmetric aliases. Changing one setting changes the other. Also account for
1827-
# existing children. Most of these are aliased due to proplot settings overlapping
1828-
# with existing matplotlib settings.
1829-
_rc_aliases = (
1832+
# Setting synonyms. Changing one setting changes the other. Also account for existing
1833+
# children. Most of these are aliased due to proplot settings overlapping with
1834+
# existing matplotlib settings.
1835+
_rc_synonyms = (
18301836
('cmap', 'image.cmap', 'cmap.sequential'),
18311837
('cmap.lut', 'image.lut'),
18321838
('font.name', 'font.family'),
@@ -1858,25 +1864,12 @@ def copy(self):
18581864
('title.size', 'axes.titlesize'),
18591865
('title.weight', 'axes.titleweight'),
18601866
)
1861-
for _keys in _rc_aliases:
1867+
for _keys in _rc_synonyms:
18621868
for _key in _keys:
18631869
_set = {_ for k in _keys for _ in {k, *_rc_children.get(k, ())}} - {_key}
18641870
_rc_children[_key] = tuple(sorted(_set))
18651871

1866-
# Recently added settings. Update these only if the version is recent enough
1867-
# NOTE: We don't make 'title.color' a child of 'axes.titlecolor' because
1868-
# the latter can take on the value 'auto' and can't handle that right now.
1869-
if dependencies._version_mpl >= 3.2:
1870-
_rc_matplotlib_default['axes.titlecolor'] = BLACK
1871-
_rc_children['title.color'] = ('axes.titlecolor',)
1872-
if dependencies._version_mpl >= 3.4:
1873-
_rc_matplotlib_default['xtick.labelcolor'] = BLACK
1874-
_rc_matplotlib_default['ytick.labelcolor'] = BLACK
1875-
_rc_children['meta.color'] += ('xtick.labelcolor', 'ytick.labelcolor')
1876-
_rc_children['tick.labelcolor'] += ('xtick.labelcolor', 'ytick.labelcolor')
1877-
_rc_children['grid.labelcolor'] += ('xtick.labelcolor', 'ytick.labelcolor')
1878-
1879-
# Deprecated settings. Add renamed settings to children dictionary so that
1872+
# Previously removed settings. Add renamed settings to children dictionary so that
18801873
# pplt.rc[deprecated] = value updates the correct children. We don't natively
18811874
# translate deprecated keys in Configurator -- leave that to the RcParams dicts.
18821875
_rc_removed = { # {key: (alternative, version)} dictionary
@@ -1937,8 +1930,23 @@ def copy(self):
19371930
if _key_new in _rc_children:
19381931
_rc_children[_key_old] = _rc_children[_key_new]
19391932

1940-
# The default settings dictionary. Analogous to matplotlib's rcParamsDefault
1941-
# Also surreptitiously add font keys (boolean always evaluates to True)
1933+
# Recently added settings. Update these only if the version is recent enough
1934+
# NOTE: We don't make 'title.color' a child of 'axes.titlecolor' because
1935+
# the latter can take on the value 'auto' and can't handle that right now.
1936+
if dependencies._version_mpl >= 3.2:
1937+
_rc_matplotlib_default['axes.titlecolor'] = BLACK
1938+
_rc_children['title.color'] = ('axes.titlecolor',)
1939+
if dependencies._version_mpl >= 3.4:
1940+
_rc_matplotlib_default['xtick.labelcolor'] = BLACK
1941+
_rc_matplotlib_default['ytick.labelcolor'] = BLACK
1942+
_rc_children['meta.color'] += ('xtick.labelcolor', 'ytick.labelcolor')
1943+
_rc_children['tick.labelcolor'] += ('xtick.labelcolor', 'ytick.labelcolor')
1944+
_rc_children['grid.labelcolor'] += ('xtick.labelcolor', 'ytick.labelcolor')
1945+
1946+
# Validate the default settings dictionaries using a custom proplot _RcParams
1947+
# and the original matplotlib RcParams. Also surreptitiously add proplot
1948+
# font settings to the font keys list (beoolean below always evalutes to True)
1949+
# font keys list whlie initializing.
19421950
_rc_proplot_default = {
19431951
key: value for key, (value, _, _) in _rc_proplot_table.items()
19441952
}
@@ -1947,6 +1955,7 @@ def copy(self):
19471955
if not (validator is _validate_fontsize and FONT_KEYS.add(key))
19481956
}
19491957
_rc_proplot_default = _RcParams(_rc_proplot_default, _rc_proplot_validate)
1958+
_rc_matplotlib_default = RcParams(_rc_matplotlib_default)
19501959

19511960
# Important joint matplotlib proplot constants
19521961
# NOTE: The 'nodots' dictionary should include removed and renamed settings

0 commit comments

Comments
 (0)