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

Skip to content

[MNT]: Cleanup ticklabel_format (style=) #26801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 20, 2023
9 changes: 6 additions & 3 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3229,7 +3229,7 @@ def grid(self, visible=None, which='major', axis='both', **kwargs):
if axis in ['y', 'both']:
self.yaxis.grid(visible, which=which, **kwargs)

def ticklabel_format(self, *, axis='both', style='', scilimits=None,
def ticklabel_format(self, *, axis='both', style=None, scilimits=None,
useOffset=None, useLocale=None, useMathText=None):
r"""
Configure the `.ScalarFormatter` used by default for linear Axes.
Expand All @@ -3245,6 +3245,7 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None,
style : {'sci', 'scientific', 'plain'}
Whether to use scientific notation.
The formatter default is to use scientific notation.
'sci' is equivalent to 'scientific'.

scilimits : pair of ints (m, n)
Scientific notation is used only for numbers outside the range
Expand Down Expand Up @@ -3274,7 +3275,8 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None,
AttributeError
If the current formatter is not a `.ScalarFormatter`.
"""
style = style.lower()
if isinstance(style, str):
style = style.lower()
axis = axis.lower()
if scilimits is not None:
try:
Expand All @@ -3283,7 +3285,8 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None,
except (ValueError, TypeError) as err:
raise ValueError("scilimits must be a sequence of 2 integers"
) from err
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None}
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None}
# The '' option is included for backwards-compatibility.
is_sci_style = _api.check_getitem(STYLES, style=style)
axis_map = {**{k: [v] for k, v in self._axis_map.items()},
'both': list(self._axis_map.values())}
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class _AxesBase(martist.Artist):
self,
*,
axis: Literal["both", "x", "y"] = ...,
style: Literal["", "sci", "scientific", "plain"] = ...,
style: Literal["", "sci", "scientific", "plain"] | None = ...,
scilimits: tuple[int, int] | None = ...,
useOffset: bool | float | None = ...,
useLocale: bool | None = ...,
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3953,7 +3953,7 @@ def tick_params(axis: Literal["both", "x", "y"] = "both", **kwargs) -> None:
def ticklabel_format(
*,
axis: Literal["both", "x", "y"] = "both",
style: Literal["", "sci", "scientific", "plain"] = "",
style: Literal["", "sci", "scientific", "plain"] | None = None,
scilimits: tuple[int, int] | None = None,
useOffset: bool | float | None = None,
useLocale: bool | None = None,
Expand Down