diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index f9c3c25bbff5..394dfc2ccafd 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -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. @@ -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 @@ -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: @@ -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())} diff --git a/lib/matplotlib/axes/_base.pyi b/lib/matplotlib/axes/_base.pyi index e3644585296d..1f929b6c90c5 100644 --- a/lib/matplotlib/axes/_base.pyi +++ b/lib/matplotlib/axes/_base.pyi @@ -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 = ..., diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 00e5dea071a4..74a73725d5d9 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -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,