From c67d1c3a604686ae7ac826db609228005df9827a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Pe=C3=A7anha?= Date: Sun, 17 Sep 2023 13:28:00 -0300 Subject: [PATCH 1/8] Changing the default value to None, adding docstring documenting and fixing extra logic. --- lib/matplotlib/axes/_base.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index f9c3c25bbff5..a8130e1910e3 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 @@ -3283,8 +3284,11 @@ 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} - is_sci_style = _api.check_getitem(STYLES, style=style) + STYLES = {'sci': True, 'scientific': True, 'plain': False} + if style == None: + is_sci_style = False + else: + 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())} axises = _api.check_getitem(axis_map, axis=axis) From b6607993610991f6b9dec153a42a2fd678df7bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Pe=C3=A7anha?= Date: Sun, 17 Sep 2023 13:44:48 -0300 Subject: [PATCH 2/8] Update _base.py Fixing if condition. --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index a8130e1910e3..8449ec066d52 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3285,7 +3285,7 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None, raise ValueError("scilimits must be a sequence of 2 integers" ) from err STYLES = {'sci': True, 'scientific': True, 'plain': False} - if style == None: + if style is None: is_sci_style = False else: is_sci_style = _api.check_getitem(STYLES, style=style) From 2096ae720c80fdcb72d45b69a0bee20dd4ef4602 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 18 Sep 2023 12:12:23 -0300 Subject: [PATCH 3/8] Added backwards-compatibility comment, changing to a solo STYLES dictionary and added stub parameter alternative. --- lib/matplotlib/axes/_base.py | 13 ++++++------- lib/matplotlib/axes/_base.pyi | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 8449ec066d52..32a8747a50a8 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3242,10 +3242,11 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None, axis : {'x', 'y', 'both'}, default: 'both' The axis to configure. Only major ticks are affected. - style : {'sci', 'scientific', 'plain'} + style : {'sci', 'scientific', 'plain', '', None}, default: None Whether to use scientific notation. The formatter default is to use scientific notation. Sci is equivalent to scientific. + The '' option is included solely for backwards-compatibility. scilimits : pair of ints (m, n) Scientific notation is used only for numbers outside the range @@ -3275,7 +3276,8 @@ def ticklabel_format(self, *, axis='both', style=None, 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: @@ -3284,11 +3286,8 @@ def ticklabel_format(self, *, axis='both', style=None, 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} - if style is None: - is_sci_style = False - else: - is_sci_style = _api.check_getitem(STYLES, style=style) + STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None} + 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())} axises = _api.check_getitem(axis_map, axis=axis) 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 = ..., From c6fdf59dfa41755c16a4ba859dfab52bad1ddbb7 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 18 Sep 2023 13:04:32 -0300 Subject: [PATCH 4/8] Changing comments from the docstring area to inline comments. --- lib/matplotlib/axes/_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 32a8747a50a8..cb6d5ba7cb41 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3242,11 +3242,9 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None, axis : {'x', 'y', 'both'}, default: 'both' The axis to configure. Only major ticks are affected. - style : {'sci', 'scientific', 'plain', '', None}, default: None + style : {'sci', 'scientific', 'plain'} or None, default: None Whether to use scientific notation. The formatter default is to use scientific notation. - Sci is equivalent to scientific. - The '' option is included solely for backwards-compatibility. scilimits : pair of ints (m, n) Scientific notation is used only for numbers outside the range @@ -3287,6 +3285,8 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None, raise ValueError("scilimits must be a sequence of 2 integers" ) from err STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None} + # 'sci' is equivalent to 'scientific'. + # 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())} From 4c3355d7d20ce4831b43224a8aebe2c178880bcb Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 19 Sep 2023 09:30:55 -0300 Subject: [PATCH 5/8] Reformatting pyplot.py and putting the sci equivalency in the docstring area. --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index cb6d5ba7cb41..23b50971b732 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3245,6 +3245,7 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None, style : {'sci', 'scientific', 'plain'} or None, default: None 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 @@ -3285,7 +3286,6 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None, raise ValueError("scilimits must be a sequence of 2 integers" ) from err STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None} - # 'sci' is equivalent to 'scientific'. # 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()}, From 558b2d843dcc27d5fb4718f4cfec28a93d431382 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 19 Sep 2023 10:05:45 -0300 Subject: [PATCH 6/8] Attempting to fix pyplot.py by hand, although this is not encouraged. --- lib/matplotlib/pyplot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 00e5dea071a4..06aef7ed686f 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, From 3cf0234d3646ef57264b8e19ddbaa6cd7d301bf7 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 19 Sep 2023 10:08:44 -0300 Subject: [PATCH 7/8] Adding a comma to pyplot.py. --- lib/matplotlib/pyplot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 06aef7ed686f..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"] | None = None + style: Literal["", "sci", "scientific", "plain"] | None = None, scilimits: tuple[int, int] | None = None, useOffset: bool | float | None = None, useLocale: bool | None = None, From 6bdc99f92ad27ba4705b0c3a4d7ee1adb74d6230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Pe=C3=A7anha?= <60028123+pedrompecanha@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:22:21 -0300 Subject: [PATCH 8/8] Editing the docstring, making it more consistent to the other parameters that default to None. Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com> --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 23b50971b732..394dfc2ccafd 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3242,7 +3242,7 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None, axis : {'x', 'y', 'both'}, default: 'both' The axis to configure. Only major ticks are affected. - style : {'sci', 'scientific', 'plain'} or None, default: None + style : {'sci', 'scientific', 'plain'} Whether to use scientific notation. The formatter default is to use scientific notation. 'sci' is equivalent to 'scientific'.