From 41cff2b8214fa580c038ca61d58b3e7faa1a0ed3 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 26 Oct 2020 23:08:31 +0100 Subject: [PATCH 1/3] Expire deprecation of unsupported parameters to axis() --- doc/api/next_api_changes/behavior/18820-TH.rst | 5 +++++ lib/matplotlib/axes/_base.py | 16 +++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 doc/api/next_api_changes/behavior/18820-TH.rst diff --git a/doc/api/next_api_changes/behavior/18820-TH.rst b/doc/api/next_api_changes/behavior/18820-TH.rst new file mode 100644 index 000000000000..57b66a05ca62 --- /dev/null +++ b/doc/api/next_api_changes/behavior/18820-TH.rst @@ -0,0 +1,5 @@ +Unsupported arguments for ``axis()`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Passing more than one positional argument or unsupported keyword arguments to +`~.Axes.axis()` now raises a ``TypeError`` (such arguments used to be silently +ignored). \ No newline at end of file diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index afe74b4e32e8..de130929f29c 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -1799,7 +1799,11 @@ def axis(self, *args, emit=True, **kwargs): matplotlib.axes.Axes.set_xlim matplotlib.axes.Axes.set_ylim """ - if len(args) == 1 and isinstance(args[0], (str, bool)): + if len(args) > 1: + raise TypeError( + f'axis() takes from 0 to 1 positional arguments but ' + f'{len(args)} were given') + if len(args) == 1 and isinstance(args[0], (str, bool)): # axis(option) s = args[0] if s is True: s = 'on' @@ -1841,15 +1845,9 @@ def axis(self, *args, emit=True, **kwargs): raise ValueError('Unrecognized string %s to axis; ' 'try on or off' % s) else: - if len(args) >= 1: - if len(args) != 1: - cbook.warn_deprecated( - "3.2", message="Passing more than one positional " - "argument to axis() is deprecated and will raise a " - "TypeError %(removal)s.") - limits = args[0] + if len(args) == 1: # axis([xmin, xmax, ymin, ymax]) try: - xmin, xmax, ymin, ymax = limits + xmin, xmax, ymin, ymax = args[0] except (TypeError, ValueError) as err: raise TypeError('the first argument to axis() must be an ' 'interable of the form ' From c9f6c0604c868a8f6071c8eda3f92a9c0f6abba7 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 26 Oct 2020 23:19:05 +0100 Subject: [PATCH 2/3] Enforce length of parameter where in fill_between() / fill_betweenx() --- doc/api/next_api_changes/behavior/18820-TH.rst | 7 ++++++- lib/matplotlib/axes/_axes.py | 7 +++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/api/next_api_changes/behavior/18820-TH.rst b/doc/api/next_api_changes/behavior/18820-TH.rst index 57b66a05ca62..a11cb2f38731 100644 --- a/doc/api/next_api_changes/behavior/18820-TH.rst +++ b/doc/api/next_api_changes/behavior/18820-TH.rst @@ -2,4 +2,9 @@ Unsupported arguments for ``axis()`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Passing more than one positional argument or unsupported keyword arguments to `~.Axes.axis()` now raises a ``TypeError`` (such arguments used to be silently -ignored). \ No newline at end of file +ignored). + +Length of parameter *where* in ``fill_between()`` and ``fill_betweenx()`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The parameter *where* in `~.Axes.fill_between()` and `~.Axes.fill_betweenx()` +must have the same length as the data points. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 30a9bbcdf2b2..8d599b3ee618 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5127,10 +5127,9 @@ def _fill_between_x_or_y( else: where = np.asarray(where, dtype=bool) if where.size != ind.size: - cbook.warn_deprecated( - "3.2", message=f"Since %(since)s, the parameter *where* " - f"must have the same size as {ind} in {func_name}(). This " - "will become an error %(removal)s.") + raise ValueError( + f"Parameters 'where' and '{ind}' must have the same size " + f"in {func_name}()") where = where & ~functools.reduce( np.logical_or, map(np.ma.getmask, [ind, dep1, dep2])) From 44d22b64b66f37441eaac0fef19d5a37143f23bb Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 26 Oct 2020 23:30:01 +0100 Subject: [PATCH 3/3] Change default padding in ``AxesDivider`` --- doc/api/next_api_changes/behavior/18820-TH.rst | 7 +++++++ lib/mpl_toolkits/axes_grid1/axes_divider.py | 13 +++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/api/next_api_changes/behavior/18820-TH.rst b/doc/api/next_api_changes/behavior/18820-TH.rst index a11cb2f38731..0ab7f60b480e 100644 --- a/doc/api/next_api_changes/behavior/18820-TH.rst +++ b/doc/api/next_api_changes/behavior/18820-TH.rst @@ -8,3 +8,10 @@ Length of parameter *where* in ``fill_between()`` and ``fill_betweenx()`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The parameter *where* in `~.Axes.fill_between()` and `~.Axes.fill_betweenx()` must have the same length as the data points. + +Default padding in ``AxesDivider`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The parameter *pad* in `.AxesDivider.new_horizontal()` now defaults to +:rc:`figure.subplot.wspace` instead of 0. +The parameter *pad* in `.AxesDivider.new_vertical()` now defaults to +:rc:`figure.subplot.hspace` instead of 0. diff --git a/lib/mpl_toolkits/axes_grid1/axes_divider.py b/lib/mpl_toolkits/axes_grid1/axes_divider.py index 2a388c18815b..1463cc22fb43 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_divider.py +++ b/lib/mpl_toolkits/axes_grid1/axes_divider.py @@ -4,6 +4,7 @@ import numpy as np +import matplotlib as mpl from matplotlib import _api, cbook from matplotlib.axes import SubplotBase from matplotlib.gridspec import SubplotSpec, GridSpec @@ -439,6 +440,7 @@ def new_horizontal(self, size, pad=None, pack_start=False, **kwargs): instance of the current axes. pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str Pad between the axes. It takes same argument as *size*. + Defaults to :rc:`figure.subplot.wspace`. pack_start : bool If False, the new axes is appended at the end of the list, i.e., it became the right-most axes. If True, it is @@ -450,10 +452,7 @@ def new_horizontal(self, size, pad=None, pack_start=False, **kwargs): main axes will be used. """ if pad is None: - cbook.warn_deprecated( - "3.2", message="In a future version, 'pad' will default to " - "rcParams['figure.subplot.wspace']. Set pad=0 to keep the " - "old behavior.") + pad = mpl.rcParams['figure.subplot.wspace'] if pad: if not isinstance(pad, Size._Base): pad = Size.from_any(pad, fraction_ref=self._xref) @@ -488,6 +487,7 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs): instance of the current axes. pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str Pad between the axes. It takes same argument as *size*. + Defaults to :rc:`figure.subplot.hspace`. pack_start : bool If False, the new axes is appended at the end of the list, i.e., it became the right-most axes. If True, it is @@ -499,10 +499,7 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs): main axes will be used. """ if pad is None: - cbook.warn_deprecated( - "3.2", message="In a future version, 'pad' will default to " - "rcParams['figure.subplot.hspace']. Set pad=0 to keep the " - "old behavior.") + pad = mpl.rcParams['figure.subplot.hspace'] if pad: if not isinstance(pad, Size._Base): pad = Size.from_any(pad, fraction_ref=self._yref)