Skip to content

Remove axes_grid/axisartist APIs deprecated in Matplotlib 3.3. #20052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions doc/api/next_api_changes/removals/20052-AL.rst
Original file line number Diff line number Diff line change
@@ -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).
59 changes: 15 additions & 44 deletions lib/mpl_toolkits/axes_grid1/axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
):
"""
Expand All @@ -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*.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down
39 changes: 6 additions & 33 deletions lib/mpl_toolkits/axes_grid1/axes_rgb.py
Original file line number Diff line number Diff line change
@@ -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
----------
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand All @@ -110,24 +98,14 @@ 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.
for ax1 in [self.RGB, self.R, self.G, self.B]:
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}.
Expand Down Expand Up @@ -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
35 changes: 5 additions & 30 deletions lib/mpl_toolkits/axes_grid1/parasite_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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), {})

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 0 additions & 11 deletions lib/mpl_toolkits/axisartist/angle_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import math

from matplotlib import _api
from mpl_toolkits.axisartist.grid_finder import ExtremeFinderSimple


Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions lib/mpl_toolkits/axisartist/axes_rgb.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
5 changes: 0 additions & 5 deletions lib/mpl_toolkits/axisartist/axis_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
20 changes: 5 additions & 15 deletions lib/mpl_toolkits/axisartist/grid_finder.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down