From b0023f52c30d9495f6b1cd20029e5e34b61a6918 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 23 Apr 2021 13:56:18 +0200 Subject: [PATCH] Remove axes_grid/axisartist APIs deprecated in Matplotlib 3.3. --- .../next_api_changes/removals/20052-AL.rst | 20 +++++++ lib/mpl_toolkits/axes_grid1/axes_grid.py | 59 +++++-------------- lib/mpl_toolkits/axes_grid1/axes_rgb.py | 39 ++---------- lib/mpl_toolkits/axes_grid1/parasite_axes.py | 35 ++--------- lib/mpl_toolkits/axisartist/angle_helper.py | 11 ---- lib/mpl_toolkits/axisartist/axes_rgb.py | 3 +- lib/mpl_toolkits/axisartist/axis_artist.py | 5 -- lib/mpl_toolkits/axisartist/grid_finder.py | 20 ++----- 8 files changed, 52 insertions(+), 140 deletions(-) create mode 100644 doc/api/next_api_changes/removals/20052-AL.rst diff --git a/doc/api/next_api_changes/removals/20052-AL.rst b/doc/api/next_api_changes/removals/20052-AL.rst new file mode 100644 index 000000000000..a250cb2bdc9a --- /dev/null +++ b/doc/api/next_api_changes/removals/20052-AL.rst @@ -0,0 +1,20 @@ +Removal of ``axes_grid``/``axisartist`` APIs deprecated in Matplotlib 3.3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The following deprecated APIs have been removed: + +- ``CbarAxesBase.cbid`` and ``CbarAxesBase.locator`` (use + ``mappable.colorbar_cid`` and ``colorbar.locator`` instead), +- the ``add_all`` parameter to ``axes_grid.Grid``, ``axes_grid.ImageGrid``, + ``axes_rgb.make_rgb_axes``, ``axes_rgb.RGBAxes`` (the APIs always behave as + if ``add_all=True``), +- ``axes_rgb.imshow_rgb`` (use ``imshow(np.dstack([r, g, b]))`` instead), +- ``RGBAxes.add_RGB_to_figure`` (no replacement), +- ``RGBAxesBase`` (use ``RGBAxes`` instead), +- passing ``None``, or no argument, to ``parasite_axes_class_factory``, + ``parasite_axes_auxtrans_class_factory``, ``host_axes_class_factory`` + (pass an explicit base class instead), +- the ``den`` parameter and attribute of ``angle_helper.LocatorBase`` (it has + been renamed to ``nbins``), +- ``AxisArtist.dpi_transform`` (no replacement), +- ``grid_finder.MaxNLocator.set_factor`` and ``grid_finder.FixedLocator.set_factor`` + (the factor is always 1 now). diff --git a/lib/mpl_toolkits/axes_grid1/axes_grid.py b/lib/mpl_toolkits/axes_grid1/axes_grid.py index 295a03ec801f..4cd5ae92ddd0 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_grid.py +++ b/lib/mpl_toolkits/axes_grid1/axes_grid.py @@ -26,25 +26,14 @@ def __init__(self, *args, orientation, **kwargs): super().__init__(*args, **kwargs) def colorbar(self, mappable, *, ticks=None, **kwargs): - - if self.orientation in ["top", "bottom"]: - orientation = "horizontal" - else: - orientation = "vertical" - + orientation = ( + "horizontal" if self.orientation in ["top", "bottom"] else + "vertical") cb = mpl.colorbar.Colorbar( self, mappable, orientation=orientation, ticks=ticks, **kwargs) - self._cbid = mappable.colorbar_cid # deprecated in 3.3. - self._locator = cb.locator # deprecated in 3.3. - self._config_axes() return cb - cbid = _api.deprecate_privatize_attribute( - "3.3", alternative="mappable.colorbar_cid") - locator = _api.deprecate_privatize_attribute( - "3.3", alternative=".colorbar().locator") - def _config_axes(self): """Make an axes patch and outline.""" ax = self @@ -80,20 +69,18 @@ class Grid: _defaultAxesClass = Axes - @_api.delete_parameter("3.3", "add_all") def __init__(self, fig, rect, nrows_ncols, ngrids=None, direction="row", axes_pad=0.02, - add_all=True, + *, share_all=False, share_x=True, share_y=True, label_mode="L", axes_class=None, - *, aspect=False, ): """ @@ -114,9 +101,6 @@ def __init__(self, fig, axes_pad : float or (float, float), default: 0.02 Padding or (horizontal padding, vertical padding) between axes, in inches. - add_all : bool, default: True - Whether to add the axes to the figure using `.Figure.add_axes`. - This parameter is deprecated. share_all : bool, default: False Whether all axes share their x- and y-axis. Overrides *share_x* and *share_y*. @@ -188,9 +172,8 @@ def __init__(self, fig, self._init_locators() - if add_all: - for ax in self.axes_all: - fig.add_axes(ax) + for ax in self.axes_all: + fig.add_axes(ax) self.set_label_mode(label_mode) @@ -335,14 +318,13 @@ class ImageGrid(Grid): _defaultCbarAxesClass = CbarAxes - @_api.delete_parameter("3.3", "add_all") def __init__(self, fig, rect, nrows_ncols, ngrids=None, direction="row", axes_pad=0.02, - add_all=True, + *, share_all=False, aspect=True, label_mode="L", @@ -372,9 +354,6 @@ def __init__(self, fig, axes_pad : float or (float, float), default: 0.02in Padding or (horizontal padding, vertical padding) between axes, in inches. - add_all : bool, default: True - Whether to add the axes to the figure using `.Figure.add_axes`. - This parameter is deprecated. share_all : bool, default: False Whether all axes share their x- and y-axis. aspect : bool, default: True @@ -409,22 +388,14 @@ def __init__(self, fig, self._colorbar_size = cbar_size # The colorbar axes are created in _init_locators(). - if add_all: - super().__init__( - fig, rect, nrows_ncols, ngrids, - direction=direction, axes_pad=axes_pad, - share_all=share_all, share_x=True, share_y=True, aspect=aspect, - label_mode=label_mode, axes_class=axes_class) - else: # Only show deprecation in that case. - super().__init__( - fig, rect, nrows_ncols, ngrids, - direction=direction, axes_pad=axes_pad, add_all=add_all, - share_all=share_all, share_x=True, share_y=True, aspect=aspect, - label_mode=label_mode, axes_class=axes_class) - - if add_all: - for ax in self.cbar_axes: - fig.add_axes(ax) + super().__init__( + fig, rect, nrows_ncols, ngrids, + direction=direction, axes_pad=axes_pad, + share_all=share_all, share_x=True, share_y=True, aspect=aspect, + label_mode=label_mode, axes_class=axes_class) + + for ax in self.cbar_axes: + fig.add_axes(ax) if cbar_set_cax: if self._colorbar_mode == "single": diff --git a/lib/mpl_toolkits/axes_grid1/axes_rgb.py b/lib/mpl_toolkits/axes_grid1/axes_rgb.py index b8cdf4dde7f1..c94f443a8f83 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_rgb.py +++ b/lib/mpl_toolkits/axes_grid1/axes_rgb.py @@ -1,12 +1,10 @@ import numpy as np -from matplotlib import _api from .axes_divider import make_axes_locatable, Size from .mpl_axes import Axes -@_api.delete_parameter("3.3", "add_all") -def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True, **kwargs): +def make_rgb_axes(ax, pad=0.01, axes_class=None, **kwargs): """ Parameters ---------- @@ -48,19 +46,13 @@ def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True, **kwargs): ax_rgb.append(ax1) - if add_all: - fig = ax.get_figure() - for ax1 in ax_rgb: - fig.add_axes(ax1) + fig = ax.get_figure() + for ax1 in ax_rgb: + fig.add_axes(ax1) return ax_rgb -@_api.deprecated("3.3", alternative="ax.imshow(np.dstack([r, g, b]))") -def imshow_rgb(ax, r, g, b, **kwargs): - return ax.imshow(np.dstack([r, g, b]), **kwargs) - - class RGBAxes: """ 4-panel imshow (RGB, R, G, B). @@ -91,16 +83,12 @@ class RGBAxes: _defaultAxesClass = Axes - @_api.delete_parameter("3.3", "add_all") - def __init__(self, *args, pad=0, add_all=True, **kwargs): + def __init__(self, *args, pad=0, **kwargs): """ Parameters ---------- pad : float, default: 0 fraction of the axes height to put as padding. - add_all : bool, default: True - Whether to add the {rgb, r, g, b} axes to the figure. - This parameter is deprecated. axes_class : matplotlib.axes.Axes *args @@ -110,10 +98,7 @@ def __init__(self, *args, pad=0, add_all=True, **kwargs): """ axes_class = kwargs.pop("axes_class", self._defaultAxesClass) self.RGB = ax = axes_class(*args, **kwargs) - if add_all: - ax.get_figure().add_axes(ax) - else: - kwargs["add_all"] = add_all # only show deprecation in that case + ax.get_figure().add_axes(ax) self.R, self.G, self.B = make_rgb_axes( ax, pad=pad, axes_class=axes_class, **kwargs) # Set the line color and ticks for the axes. @@ -121,13 +106,6 @@ def __init__(self, *args, pad=0, add_all=True, **kwargs): ax1.axis[:].line.set_color("w") ax1.axis[:].major_ticks.set_markeredgecolor("w") - @_api.deprecated("3.3") - def add_RGB_to_figure(self): - """Add red, green and blue axes to the RGB composite's axes figure.""" - self.RGB.get_figure().add_axes(self.R) - self.RGB.get_figure().add_axes(self.G) - self.RGB.get_figure().add_axes(self.B) - def imshow_rgb(self, r, g, b, **kwargs): """ Create the four images {rgb, r, g, b}. @@ -161,8 +139,3 @@ def imshow_rgb(self, r, g, b, **kwargs): im_g = self.G.imshow(G, **kwargs) im_b = self.B.imshow(B, **kwargs) return im_rgb, im_r, im_g, im_b - - -@_api.deprecated("3.3", alternative="RGBAxes") -class RGBAxesBase(RGBAxes): - pass diff --git a/lib/mpl_toolkits/axes_grid1/parasite_axes.py b/lib/mpl_toolkits/axes_grid1/parasite_axes.py index eea567ff5fd5..2bb7d006a405 100644 --- a/lib/mpl_toolkits/axes_grid1/parasite_axes.py +++ b/lib/mpl_toolkits/axes_grid1/parasite_axes.py @@ -95,15 +95,7 @@ def apply_aspect(self, position=None): @functools.lru_cache(None) -def parasite_axes_class_factory(axes_class=None): - if axes_class is None: - _api.warn_deprecated( - "3.3", message="Support for passing None to " - "parasite_axes_class_factory is deprecated since %(since)s and " - "will be removed %(removal)s; explicitly pass the default Axes " - "class instead.") - axes_class = Axes - +def parasite_axes_class_factory(axes_class): return type("%sParasite" % axes_class.__name__, (ParasiteAxesBase, axes_class), {}) @@ -158,15 +150,8 @@ def apply_aspect(self, position=None): @_api.deprecated("3.4", alternative="parasite_axes_class_factory") @functools.lru_cache(None) -def parasite_axes_auxtrans_class_factory(axes_class=None): - if axes_class is None: - _api.warn_deprecated( - "3.3", message="Support for passing None to " - "parasite_axes_auxtrans_class_factory is deprecated since " - "%(since)s and will be removed %(removal)s; explicitly pass the " - "default ParasiteAxes class instead.") - parasite_axes_class = ParasiteAxes - elif not issubclass(axes_class, ParasiteAxesBase): +def parasite_axes_auxtrans_class_factory(axes_class): + if not issubclass(axes_class, ParasiteAxesBase): parasite_axes_class = parasite_axes_class_factory(axes_class) else: parasite_axes_class = axes_class @@ -326,20 +311,10 @@ def get_tightbbox(self, renderer, call_axes_locator=True, @functools.lru_cache(None) -def host_axes_class_factory(axes_class=None): - if axes_class is None: - _api.warn_deprecated( - "3.3", message="Support for passing None to host_axes_class is " - "deprecated since %(since)s and will be removed %(removed)s; " - "explicitly pass the default Axes class instead.") - axes_class = Axes - - def _get_base_axes(self): - return axes_class - +def host_axes_class_factory(axes_class): return type("%sHostAxes" % axes_class.__name__, (HostAxesBase, axes_class), - {'_get_base_axes': _get_base_axes}) + {'_get_base_axes': lambda self: axes_class}) def host_subplot_class_factory(axes_class): diff --git a/lib/mpl_toolkits/axisartist/angle_helper.py b/lib/mpl_toolkits/axisartist/angle_helper.py index 041bf443b766..7f49a657ba52 100644 --- a/lib/mpl_toolkits/axisartist/angle_helper.py +++ b/lib/mpl_toolkits/axisartist/angle_helper.py @@ -1,7 +1,6 @@ import numpy as np import math -from matplotlib import _api from mpl_toolkits.axisartist.grid_finder import ExtremeFinderSimple @@ -141,20 +140,10 @@ def select_step360(v1, v2, nv, include_last=True, threshold_factor=3600): class LocatorBase: - @_api.rename_parameter("3.3", "den", "nbins") def __init__(self, nbins, include_last=True): self.nbins = nbins self._include_last = include_last - @_api.deprecated("3.3", alternative="nbins") - @property - def den(self): - return self.nbins - - @den.setter - def den(self, v): - self.nbins = v - def set_params(self, nbins=None): if nbins is not None: self.nbins = int(nbins) diff --git a/lib/mpl_toolkits/axisartist/axes_rgb.py b/lib/mpl_toolkits/axisartist/axes_rgb.py index 429843f6f4b9..8c1d24bc3787 100644 --- a/lib/mpl_toolkits/axisartist/axes_rgb.py +++ b/lib/mpl_toolkits/axisartist/axes_rgb.py @@ -1,5 +1,4 @@ -from mpl_toolkits.axes_grid1.axes_rgb import ( - make_rgb_axes, imshow_rgb, RGBAxes as _RGBAxes) +from mpl_toolkits.axes_grid1.axes_rgb import make_rgb_axes, RGBAxes as _RGBAxes from .axislines import Axes diff --git a/lib/mpl_toolkits/axisartist/axis_artist.py b/lib/mpl_toolkits/axisartist/axis_artist.py index 21d9eff8ea34..be055e9fa966 100644 --- a/lib/mpl_toolkits/axisartist/axis_artist.py +++ b/lib/mpl_toolkits/axisartist/axis_artist.py @@ -673,11 +673,6 @@ def __init__(self, axes, self._axislabel_add_angle = 0. self.set_axis_direction(axis_direction) - @_api.deprecated("3.3") - @property - def dpi_transform(self): - return Affine2D().scale(1 / 72) + self.axes.figure.dpi_scale_trans - # axis direction def set_axis_direction(self, axis_direction): diff --git a/lib/mpl_toolkits/axisartist/grid_finder.py b/lib/mpl_toolkits/axisartist/grid_finder.py index 5bc18be381d1..2fe4d8bf79eb 100644 --- a/lib/mpl_toolkits/axisartist/grid_finder.py +++ b/lib/mpl_toolkits/axisartist/grid_finder.py @@ -1,6 +1,6 @@ import numpy as np -from matplotlib import _api, ticker as mticker +from matplotlib import ticker as mticker from matplotlib.transforms import Bbox, Transform from .clip_path import clip_line_to_rect @@ -219,30 +219,20 @@ def __init__(self, nbins=10, steps=None, super().__init__(nbins, steps=steps, integer=integer, symmetric=symmetric, prune=prune) self.create_dummy_axis() - self._factor = 1 def __call__(self, v1, v2): - locs = super().tick_values(v1 * self._factor, v2 * self._factor) - return np.array(locs), len(locs), self._factor - - @_api.deprecated("3.3") - def set_factor(self, f): - self._factor = f + locs = super().tick_values(v1, v2) + return np.array(locs), len(locs), 1 # 1: factor (see angle_helper) class FixedLocator: def __init__(self, locs): self._locs = locs - self._factor = 1 def __call__(self, v1, v2): - v1, v2 = sorted([v1 * self._factor, v2 * self._factor]) + v1, v2 = sorted([v1, v2]) locs = np.array([l for l in self._locs if v1 <= l <= v2]) - return locs, len(locs), self._factor - - @_api.deprecated("3.3") - def set_factor(self, f): - self._factor = f + return locs, len(locs), 1 # 1: factor (see angle_helper) # Tick Formatter