From 7ae511a6f5329320a73e7103db29b4a5b08185c5 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 24 Apr 2024 22:19:07 +0200 Subject: [PATCH] Make `functions` param to secondary_x/yaxis not keyword-only. I suspect the parameter was made keyword-only because the originally planned signature was `secondary_xaxis(location, forward=..., inverse=...)` where the keywords actually add some semantics (though that signature overall seems worse); however, for a single `functions` parameter, having to type an extra `functions=` in the call doesn't help the reader much (either they know what secondary_x/yaxis does, in which case the explicit kwarg doesn't matter, or they don't, in which case the kwarg name hardly helps)... and is a bit annoying. See the modified gallery entry, for example. --- galleries/users_explain/quick_start.py | 2 +- lib/matplotlib/axes/_axes.py | 4 ++-- lib/matplotlib/axes/_axes.pyi | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/galleries/users_explain/quick_start.py b/galleries/users_explain/quick_start.py index 1970f71f737c..b525af40b9a6 100644 --- a/galleries/users_explain/quick_start.py +++ b/galleries/users_explain/quick_start.py @@ -496,7 +496,7 @@ def my_plotter(ax, data1, data2, param_dict): ax3.plot(t, s) ax3.set_xlabel('Angle [rad]') -ax4 = ax3.secondary_xaxis('top', functions=(np.rad2deg, np.deg2rad)) +ax4 = ax3.secondary_xaxis('top', (np.rad2deg, np.deg2rad)) ax4.set_xlabel('Angle [°]') # %% diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 45a039d49928..9b1a2c629889 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -570,7 +570,7 @@ def indicate_inset_zoom(self, inset_ax, **kwargs): return self.indicate_inset(rect, inset_ax, **kwargs) @_docstring.dedent_interpd - def secondary_xaxis(self, location, *, functions=None, transform=None, **kwargs): + def secondary_xaxis(self, location, functions=None, *, transform=None, **kwargs): """ Add a second x-axis to this `~.axes.Axes`. @@ -624,7 +624,7 @@ def invert(x): return secondary_ax @_docstring.dedent_interpd - def secondary_yaxis(self, location, *, functions=None, transform=None, **kwargs): + def secondary_yaxis(self, location, functions=None, *, transform=None, **kwargs): """ Add a second y-axis to this `~.axes.Axes`. diff --git a/lib/matplotlib/axes/_axes.pyi b/lib/matplotlib/axes/_axes.pyi index be0a0e48d662..007499f23381 100644 --- a/lib/matplotlib/axes/_axes.pyi +++ b/lib/matplotlib/axes/_axes.pyi @@ -88,24 +88,24 @@ class Axes(_AxesBase): def secondary_xaxis( self, location: Literal["top", "bottom"] | float, - *, functions: tuple[ Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike] ] | Transform | None = ..., + *, transform: Transform | None = ..., **kwargs ) -> SecondaryAxis: ... def secondary_yaxis( self, location: Literal["left", "right"] | float, - *, functions: tuple[ Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike] ] | Transform | None = ..., + *, transform: Transform | None = ..., **kwargs ) -> SecondaryAxis: ...