Skip to content

Commit 3a7e5a7

Browse files
committed
Change 'autoformat' from Figure kwarg to rc setting
1 parent d8fe419 commit 3a7e5a7

File tree

4 files changed

+41
-31
lines changed

4 files changed

+41
-31
lines changed

proplot/axes/plot.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666
Whether *x* axis labels, *y* axis labels, axis formatters, axes titles,
6767
colorbar labels, and legend labels are automatically configured when
6868
a `~pandas.Series`, `~pandas.DataFrame` or `~xarray.DataArray` is passed
69-
to the plotting command. Default is the figure-wide
70-
`proplot.figure.Figure.autoformat` setting.
69+
to the plotting command. Default is :rc:`autoformat`.
7170
"""
7271

7372
docstring.snippets['axes.cmap_changer'] = """
@@ -458,7 +457,6 @@ def standardize_1d(self, func, *args, autoformat=None, **kwargs):
458457
# Sanitize input
459458
# TODO: Add exceptions for methods other than 'hist'?
460459
name = func.__name__
461-
autoformat = _not_none(autoformat, self.figure._auto_format)
462460
_load_objects()
463461
if not args:
464462
return func(self, *args, **kwargs)
@@ -554,7 +552,8 @@ def standardize_1d(self, func, *args, autoformat=None, **kwargs):
554552

555553
# WARNING: For some functions, e.g. boxplot and violinplot, we *require*
556554
# cycle_changer is also applied so it can strip 'x' input.
557-
with _state_context(self, _auto_format=autoformat):
555+
autoformat = _not_none(autoformat, rc['autoformat'])
556+
with rc.context(autoformat=autoformat):
558557
return func(self, x, *ys, *args, **kwargs)
559558

560559

@@ -679,7 +678,6 @@ def standardize_2d(
679678
"""
680679
# Sanitize input
681680
name = func.__name__
682-
autoformat = _not_none(autoformat, self.figure._auto_format)
683681
_load_objects()
684682
if not args:
685683
return func(self, *args, **kwargs)
@@ -933,7 +931,8 @@ def standardize_2d(
933931
kwargs['latlon'] = False
934932

935933
# Finally return result
936-
with _state_context(self, _auto_format=autoformat):
934+
autoformat = _not_none(autoformat, rc['autoformat'])
935+
with rc.context(autoformat=autoformat):
937936
return func(self, x, y, *Zs, **kwargs)
938937

939938

@@ -1100,20 +1099,22 @@ def indicate_error(
11001099
calculated automatically).
11011100
boxstds, boxpctiles, boxdata : optional
11021101
As with `barstds`, `barpctiles`, and `bardata`, but for *thicker error bars*
1103-
representing a smaller interval than thick error bars. If `boxstds` is
1102+
representing a smaller interval than the thin error bars. If `boxstds` is
11041103
``True``, the default standard deviation multiples ``(-1, 1)`` are used.
11051104
If `boxpctiles` is ``True``, the default percentile multiples ``(25, 75)``
1106-
(i.e. the interquartile range) are used. When boxes and bars are combined, this
1105+
are used (i.e. the interquartile range). When boxes and bars are combined, this
11071106
has the effect of drawing miniature box-and-whisker plots.
11081107
shadestds, shadepctiles, shadedata : optional
11091108
As with `barstds`, `barpctiles`, and `bardata`, but using *shading* to indicate
11101109
the error range. If `shadestds` is ``True``, the default standard deviation
11111110
multiples ``(-2, 2)`` are used. If `shadepctiles` is ``True``, the default
1112-
percentile multiples ``(5, 95)`` are used. Shading is generally useful for
1111+
percentile multiples ``(10, 90)`` are used. Shading is generally useful for
11131112
`~matplotlib.axes.Axes.plot` plots and not `~matplotlib.axes.Axes.bar` plots.
11141113
fadestds, fadepctiles, fadedata : optional
11151114
As with `shadestds`, `shadepctiles`, and `shadedata`, but for an additional,
1116-
more faded, *secondary* shaded region.
1115+
more faded, *secondary* shaded region. If `fadestds` is ``True``, the default
1116+
standard deviation multiples ``(-3, 3)`` are used. If `fadepctiles` is ``True``,
1117+
the default percentile multiples ``(0, 100)`` are used.
11171118
barcolor, boxcolor, shadecolor, fadecolor : color-spec, optional
11181119
Colors for the different error indicators. For error bars, the default is
11191120
``'k'``. For shading, the default behavior is to inherit color from the
@@ -2255,7 +2256,7 @@ def cycle_changer(
22552256
# NOTE: Requires standardize_1d wrapper before reaching this. Also note
22562257
# that the 'x' coordinates are sometimes ignored below.
22572258
name = func.__name__
2258-
autoformat = self._auto_format # possibly manipulated by standardize_[12]d
2259+
autoformat = rc['autoformat'] # possibly manipulated by standardize_[12]d
22592260
if not args:
22602261
return func(self, *args, **kwargs)
22612262
x, y, *args = args
@@ -2846,7 +2847,7 @@ def cmap_changer(
28462847
of the color selections.
28472848
"""
28482849
name = func.__name__
2849-
autoformat = self._auto_format # possibly manipulated by standardize_[12]d
2850+
autoformat = rc['autoformat'] # possibly manipulated by standardize_[12]d
28502851
if not args:
28512852
return func(self, *args, **kwargs)
28522853

proplot/figure.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,17 @@ class Figure(mfigure.Figure):
124124
Figure dimensions may be automatically scaled to preserve subplot aspect
125125
ratios.
126126
"""
127+
# NOTE: If _rename_kwargs argument is an invalid identifier, it is
128+
# simply used in the warning message.
129+
@warnings._rename_kwargs('0.6.4', autoformat='plot.rc.autoformat = {}')
127130
def __init__(
128131
self, tight=None,
129132
ref=1, pad=None, axpad=None, panelpad=None, includepanels=False,
130133
span=None, spanx=None, spany=None,
131134
align=None, alignx=None, aligny=None,
132135
share=None, sharex=None, sharey=None,
133-
autoformat=True, fallback_to_cm=None,
134136
gridspec_kw=None, subplots_kw=None, subplots_orig_kw=None,
137+
fallback_to_cm=None,
135138
**kwargs
136139
):
137140
"""
@@ -189,11 +192,6 @@ def __init__(
189192
<https://matplotlib.org/3.1.1/gallery/subplots_axes_and_figures/align_labels_demo.html>`__
190193
for the *x* axis, *y* axis, or both axes. Only has an effect when `spanx`,
191194
`spany`, or `span` are ``False``. Default is :rc:`subplots.align`.
192-
autoformat : bool, optional
193-
Whether to automatically configure *x* axis labels, *y* axis labels,
194-
axis formatters, axes titles, colorbar labels, and legend labels when
195-
a `~pandas.Series`, `~pandas.DataFrame` or `~xarray.DataArray` with
196-
relevant metadata is passed to a plotting command.
197195
fallback_to_cm : bool, optional
198196
Whether to replace unavailable glyphs with a glyph from Computer Modern
199197
or the "¤" dummy character. See `mathtext \
@@ -266,7 +264,6 @@ def __init__(
266264
self._pad = units(_not_none(pad, rc['subplots.pad']))
267265
self._axpad = units(_not_none(axpad, rc['subplots.axpad']))
268266
self._panelpad = units(_not_none(panelpad, rc['subplots.panelpad']))
269-
self._auto_format = autoformat
270267
self._auto_tight = _not_none(tight, rc['subplots.tight'])
271268
self._include_panels = includepanels
272269
self._fallback_to_cm = fallback_to_cm
@@ -1402,9 +1399,9 @@ def _iter_axes(self, hidden=False, children=False):
14021399
# Deprecations
14031400
# NOTE: None of these even *worked* after drawing the figure. And not sure
14041401
# what value (if any) they add even if we do get them to work.
1405-
get_alignx, set_alignx = warnings._read_only_property('0.6', 'alignx')
1406-
get_aligny, set_aligny = warnings._read_only_property('0.6', 'aligny')
1407-
get_sharex, set_sharex = warnings._read_only_property('0.6', 'sharex')
1408-
get_sharey, set_sharey = warnings._read_only_property('0.6', 'sharey')
1409-
get_spanx, set_spanx = warnings._read_only_property('0.6', 'spanx')
1410-
get_spany, set_spany = warnings._read_only_property('0.6', 'spany')
1402+
get_alignx, set_alignx = warnings._deprecate_getter_setter('0.6', 'alignx')
1403+
get_aligny, set_aligny = warnings._deprecate_getter_setter('0.6', 'aligny')
1404+
get_sharex, set_sharex = warnings._deprecate_getter_setter('0.6', 'sharex')
1405+
get_sharey, set_sharey = warnings._deprecate_getter_setter('0.6', 'sharey')
1406+
get_spanx, set_spanx = warnings._deprecate_getter_setter('0.6', 'spanx')
1407+
get_spany, set_spany = warnings._deprecate_getter_setter('0.6', 'spany')

proplot/internals/rcsetup.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,21 @@
285285
'bold',
286286
'a-b-c label font weight.'
287287
),
288+
'autoformat': (
289+
True,
290+
'Whether to automatically apply labels from `pandas.Series`, '
291+
'`pandas.DataFrame`, and `xarray.DataArray` objects passed to '
292+
'plotting functions.'
293+
),
288294

289295
# Axes additions
290296
'alpha': (
291-
1,
297+
1.0,
292298
'The opacity of the background axes patch.'
293299
),
294300
'axes.alpha': (
295301
1.0,
296-
'Opacity of the background axes patch.'
302+
'The opacity of the background axes patch.'
297303
),
298304
'formatter.timerotation': (
299305
90,

proplot/internals/warnings.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _warn_proplot(message):
2727
warnings.warn(message, stacklevel=2)
2828

2929

30-
def _read_only_property(version, property):
30+
def _deprecate_getter_setter(version, property):
3131
"""
3232
Generate `set_name` and `get_name` methods for property setters and getters,
3333
and issue warnings when they are used.
@@ -80,15 +80,21 @@ def wrapper(*args, **kwargs):
8080
def _rename_kwargs(version, **kwargs_rename):
8181
"""
8282
Emit a basic deprecation warning after removing or renaming function keyword
83-
arguments. Each key should be an old keyword, and each arguments should be the
84-
new keyword or a tuple of new keyword options.
83+
arguments. Each key should be an old keyword, and each argument should be the
84+
new keyword or *instructions* for what to use instead.
8585
"""
8686
def decorator(func_orig):
8787
@functools.wraps(func_orig)
8888
def wrapper(*args, **kwargs):
8989
for key_old, key_new in kwargs_rename.items():
9090
if key_old in kwargs:
91-
kwargs[key_new] = kwargs.pop(key_old)
91+
value = kwargs.pop(key_old)
92+
if key_new.isidentifier():
93+
# Rename argument
94+
kwargs[key_new] = value
95+
elif '{}' in key_new:
96+
# Nice warning message, but user's desired behavior fails
97+
key_new = key_new.format(value)
9298
_warn_proplot(
9399
f'Keyword arg {key_old!r} was deprecated in {version} and '
94100
'will be removed in the next major release. '

0 commit comments

Comments
 (0)