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

Skip to content

Commit 2cbdff8

Browse files
authored
Merge pull request #26801 from pedrompecanha/cleanup-ticklabel
[MNT]: Cleanup ticklabel_format (style=)
2 parents ab1b6a3 + 6bdc99f commit 2cbdff8

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,7 @@ def grid(self, visible=None, which='major', axis='both', **kwargs):
32223222
if axis in ['y', 'both']:
32233223
self.yaxis.grid(visible, which=which, **kwargs)
32243224

3225-
def ticklabel_format(self, *, axis='both', style='', scilimits=None,
3225+
def ticklabel_format(self, *, axis='both', style=None, scilimits=None,
32263226
useOffset=None, useLocale=None, useMathText=None):
32273227
r"""
32283228
Configure the `.ScalarFormatter` used by default for linear Axes.
@@ -3238,6 +3238,7 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None,
32383238
style : {'sci', 'scientific', 'plain'}
32393239
Whether to use scientific notation.
32403240
The formatter default is to use scientific notation.
3241+
'sci' is equivalent to 'scientific'.
32413242
32423243
scilimits : pair of ints (m, n)
32433244
Scientific notation is used only for numbers outside the range
@@ -3267,7 +3268,8 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None,
32673268
AttributeError
32683269
If the current formatter is not a `.ScalarFormatter`.
32693270
"""
3270-
style = style.lower()
3271+
if isinstance(style, str):
3272+
style = style.lower()
32713273
axis = axis.lower()
32723274
if scilimits is not None:
32733275
try:
@@ -3276,7 +3278,8 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None,
32763278
except (ValueError, TypeError) as err:
32773279
raise ValueError("scilimits must be a sequence of 2 integers"
32783280
) from err
3279-
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None}
3281+
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None}
3282+
# The '' option is included for backwards-compatibility.
32803283
is_sci_style = _api.check_getitem(STYLES, style=style)
32813284
axis_map = {**{k: [v] for k, v in self._axis_map.items()},
32823285
'both': list(self._axis_map.values())}

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 = ...,

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3953,7 +3953,7 @@ def tick_params(axis: Literal["both", "x", "y"] = "both", **kwargs) -> None:
39533953
def ticklabel_format(
39543954
*,
39553955
axis: Literal["both", "x", "y"] = "both",
3956-
style: Literal["", "sci", "scientific", "plain"] = "",
3956+
style: Literal["", "sci", "scientific", "plain"] | None = None,
39573957
scilimits: tuple[int, int] | None = None,
39583958
useOffset: bool | float | None = None,
39593959
useLocale: bool | None = None,

0 commit comments

Comments
 (0)