From 5de0a17e4f7ab1d1d09ac6e9694bf1021568c483 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 26 Feb 2020 10:56:01 +0100 Subject: [PATCH] Dynamically generate CbarAxes. This is a followup to the introduction of _make_class_factory, and avoids having to define a separate CbarAxes class in axisartist. --- doc/api/next_api_changes/deprecations/20606-AL.rst | 4 ++++ lib/mpl_toolkits/axes_grid1/axes_grid.py | 10 ++++++---- lib/mpl_toolkits/axisartist/axes_grid.py | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 doc/api/next_api_changes/deprecations/20606-AL.rst diff --git a/doc/api/next_api_changes/deprecations/20606-AL.rst b/doc/api/next_api_changes/deprecations/20606-AL.rst new file mode 100644 index 000000000000..63a728510e4d --- /dev/null +++ b/doc/api/next_api_changes/deprecations/20606-AL.rst @@ -0,0 +1,4 @@ +``axes_grid1.axes_grid.CbarAxes`` and ``axes_grid1.axisartist.CbarAxes`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +These classes are deprecated (they are now dynamically generated based on the +owning axes class). diff --git a/lib/mpl_toolkits/axes_grid1/axes_grid.py b/lib/mpl_toolkits/axes_grid1/axes_grid.py index 58b111865aa0..3198ab2b3bdf 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_grid.py +++ b/lib/mpl_toolkits/axes_grid1/axes_grid.py @@ -3,7 +3,7 @@ import numpy as np -from matplotlib import _api +from matplotlib import _api, cbook from matplotlib.gridspec import SubplotSpec from .axes_divider import Size, SubplotDivider, Divider @@ -43,10 +43,14 @@ def cla(self): self.orientation = orientation +@_api.deprecated("3.5") class CbarAxes(CbarAxesBase, Axes): pass +_cbaraxes_class_factory = cbook._make_class_factory(CbarAxesBase, "Cbar{}") + + class Grid: """ A grid of Axes. @@ -310,8 +314,6 @@ def get_vsize_hsize(self): class ImageGrid(Grid): # docstring inherited - _defaultCbarAxesClass = CbarAxes - def __init__(self, fig, rect, nrows_ncols, @@ -416,7 +418,7 @@ def _init_locators(self): else: self._colorbar_pad = self._vert_pad_size.fixed_size self.cbar_axes = [ - self._defaultCbarAxesClass( + _cbaraxes_class_factory(self._defaultAxesClass)( self.axes_all[0].figure, self._divider.get_position(), orientation=self._colorbar_location) for _ in range(self.ngrids)] diff --git a/lib/mpl_toolkits/axisartist/axes_grid.py b/lib/mpl_toolkits/axisartist/axes_grid.py index 15c715b72896..d90097228329 100644 --- a/lib/mpl_toolkits/axisartist/axes_grid.py +++ b/lib/mpl_toolkits/axisartist/axes_grid.py @@ -1,7 +1,9 @@ +from matplotlib import _api import mpl_toolkits.axes_grid1.axes_grid as axes_grid_orig from .axislines import Axes +@_api.deprecated("3.5") class CbarAxes(axes_grid_orig.CbarAxesBase, Axes): pass @@ -12,7 +14,6 @@ class Grid(axes_grid_orig.Grid): class ImageGrid(axes_grid_orig.ImageGrid): _defaultAxesClass = Axes - _defaultCbarAxesClass = CbarAxes AxesGrid = ImageGrid