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

Skip to content

Commit 2096ae7

Browse files
committed
Added backwards-compatibility comment, changing to a solo STYLES dictionary and added stub parameter alternative.
1 parent b660799 commit 2096ae7

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,10 +3242,11 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None,
32423242
axis : {'x', 'y', 'both'}, default: 'both'
32433243
The axis to configure. Only major ticks are affected.
32443244
3245-
style : {'sci', 'scientific', 'plain'}
3245+
style : {'sci', 'scientific', 'plain', '', None}, default: None
32463246
Whether to use scientific notation.
32473247
The formatter default is to use scientific notation.
32483248
Sci is equivalent to scientific.
3249+
The '' option is included solely for backwards-compatibility.
32493250
32503251
scilimits : pair of ints (m, n)
32513252
Scientific notation is used only for numbers outside the range
@@ -3275,7 +3276,8 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None,
32753276
AttributeError
32763277
If the current formatter is not a `.ScalarFormatter`.
32773278
"""
3278-
style = style.lower()
3279+
if isinstance(style, str):
3280+
style = style.lower()
32793281
axis = axis.lower()
32803282
if scilimits is not None:
32813283
try:
@@ -3284,11 +3286,8 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None,
32843286
except (ValueError, TypeError) as err:
32853287
raise ValueError("scilimits must be a sequence of 2 integers"
32863288
) from err
3287-
STYLES = {'sci': True, 'scientific': True, 'plain': False}
3288-
if style is None:
3289-
is_sci_style = False
3290-
else:
3291-
is_sci_style = _api.check_getitem(STYLES, style=style)
3289+
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None}
3290+
is_sci_style = _api.check_getitem(STYLES, style=style)
32923291
axis_map = {**{k: [v] for k, v in self._axis_map.items()},
32933292
'both': list(self._axis_map.values())}
32943293
axises = _api.check_getitem(axis_map, axis=axis)

lib/matplotlib/axes/_base.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class _AxesBase(martist.Artist):
283283
self,
284284
*,
285285
axis: Literal["both", "x", "y"] = ...,
286-
style: Literal["", "sci", "scientific", "plain"] = ...,
286+
style: Literal["", "sci", "scientific", "plain"] | None = ...,
287287
scilimits: tuple[int, int] | None = ...,
288288
useOffset: bool | float | None = ...,
289289
useLocale: bool | None = ...,

0 commit comments

Comments
 (0)