From 3c559d8836e616c4e39ca251daa91f019964b331 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 4 Oct 2020 20:59:15 +0200 Subject: [PATCH] Sync SubplotDivider API with SubplotBase API changes. The deprecations parallel the ones in 261f706. --- .../deprecations/18564-AL.rst | 21 +++++++++-------- lib/mpl_toolkits/axes_grid1/axes_divider.py | 23 ++++++++++++------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/doc/api/next_api_changes/deprecations/18564-AL.rst b/doc/api/next_api_changes/deprecations/18564-AL.rst index e5314e54bb3b..d4e38763a196 100644 --- a/doc/api/next_api_changes/deprecations/18564-AL.rst +++ b/doc/api/next_api_changes/deprecations/18564-AL.rst @@ -1,14 +1,17 @@ Subplot-related attributes and methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Some ``SubplotBase`` attributes have been deprecated and/or moved to -`.SubplotSpec`: ``get_geometry`` (use `.SubplotBase.get_subplotspec` -instead), ``change_geometry`` (use `.SubplotBase.set_subplotspec` instead), -``is_first_row``, ``is_last_row``, ``is_first_col``, ``is_last_col`` (use the -corresponding methods on the `.SubplotSpec` instance instead), ``figbox`` (use -``ax.get_subplotspec().get_geometry(ax.figure)`` instead to recompute the -geometry, or ``ax.get_position()`` to read its current value), ``numRows``, -``numCols`` (use the ``nrows`` and ``ncols`` attribute on the `.GridSpec` -instead). +Some ``SubplotBase`` methods and attributes have been deprecated and/or moved +to `.SubplotSpec`: ``get_geometry`` (use `.SubplotBase.get_subplotspec` +instead), ``change_geometry`` (use `.SubplotBase.set_subplotspec` +instead), ``is_first_row``, ``is_last_row``, ``is_first_col``, +``is_last_col`` (use the corresponding methods on the `.SubplotSpec` +instance instead), ``update_params`` (now a no-op), ``figbox`` (use +``ax.get_subplotspec().get_geometry(ax.figure)`` instead to recompute +the geometry, or ``ax.get_position()`` to read its current value), +``numRows``, ``numCols`` (use the ``nrows`` and ``ncols`` attribute on the +`.GridSpec` instead). Likewise, the ``get_geometry``, ``change_geometry``, +``update_params``, and ``figbox`` methods/attributes of `.SubplotDivider` have +been deprecated, with similar replacements. Axes constructor ~~~~~~~~~~~~~~~~ diff --git a/lib/mpl_toolkits/axes_grid1/axes_divider.py b/lib/mpl_toolkits/axes_grid1/axes_divider.py index 49b5333e5ace..11c302007cea 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_divider.py +++ b/lib/mpl_toolkits/axes_grid1/axes_divider.py @@ -347,27 +347,33 @@ def __init__(self, fig, *args, horizontal=None, vertical=None, (2, 3, 4)). """ self.figure = fig - self._subplotspec = SubplotSpec._from_subplot_args(fig, args) - self.update_params() # sets self.figbox - super().__init__(fig, pos=self.figbox.bounds, + super().__init__(fig, [0, 0, 1, 1], horizontal=horizontal or [], vertical=vertical or [], aspect=aspect, anchor=anchor) + self.set_subplotspec(SubplotSpec._from_subplot_args(fig, args)) def get_position(self): """Return the bounds of the subplot box.""" - self.update_params() # update self.figbox - return self.figbox.bounds + return self.get_subplotspec().get_position(self.figure).bounds + @cbook.deprecated("3.4") + @property + def figbox(self): + return self.get_subplotspec().get_position(self.figure) + + @cbook.deprecated("3.4") def update_params(self): - """Update the subplot position from fig.subplotpars.""" - self.figbox = self.get_subplotspec().get_position(self.figure) + pass + @cbook.deprecated( + "3.4", alternative="get_subplotspec", + addendum="(get_subplotspec returns a SubplotSpec instance.)") def get_geometry(self): """Get the subplot geometry, e.g., (2, 2, 3).""" rows, cols, num1, num2 = self.get_subplotspec().get_geometry() return rows, cols, num1 + 1 # for compatibility - # COVERAGE NOTE: Never used internally or from examples + @cbook.deprecated("3.4", alternative="set_subplotspec") def change_geometry(self, numrows, numcols, num): """Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3).""" self._subplotspec = GridSpec(numrows, numcols)[num-1] @@ -381,6 +387,7 @@ def get_subplotspec(self): def set_subplotspec(self, subplotspec): """Set the SubplotSpec instance.""" self._subplotspec = subplotspec + self.set_position(subplotspec.get_position(self.figure)) class AxesDivider(Divider):