Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45494c5

Browse files
authored
Merge pull request #18655 from anntzer/sd
Sync SubplotDivider API with SubplotBase API changes.
2 parents 776ae79 + 3c559d8 commit 45494c5

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

doc/api/next_api_changes/deprecations/18564-AL.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
Subplot-related attributes and methods
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3-
Some ``SubplotBase`` attributes have been deprecated and/or moved to
4-
`.SubplotSpec`: ``get_geometry`` (use `.SubplotBase.get_subplotspec`
5-
instead), ``change_geometry`` (use `.SubplotBase.set_subplotspec` instead),
6-
``is_first_row``, ``is_last_row``, ``is_first_col``, ``is_last_col`` (use the
7-
corresponding methods on the `.SubplotSpec` instance instead), ``figbox`` (use
8-
``ax.get_subplotspec().get_geometry(ax.figure)`` instead to recompute the
9-
geometry, or ``ax.get_position()`` to read its current value), ``numRows``,
10-
``numCols`` (use the ``nrows`` and ``ncols`` attribute on the `.GridSpec`
11-
instead).
3+
Some ``SubplotBase`` methods and attributes have been deprecated and/or moved
4+
to `.SubplotSpec`: ``get_geometry`` (use `.SubplotBase.get_subplotspec`
5+
instead), ``change_geometry`` (use `.SubplotBase.set_subplotspec`
6+
instead), ``is_first_row``, ``is_last_row``, ``is_first_col``,
7+
``is_last_col`` (use the corresponding methods on the `.SubplotSpec`
8+
instance instead), ``update_params`` (now a no-op), ``figbox`` (use
9+
``ax.get_subplotspec().get_geometry(ax.figure)`` instead to recompute
10+
the geometry, or ``ax.get_position()`` to read its current value),
11+
``numRows``, ``numCols`` (use the ``nrows`` and ``ncols`` attribute on the
12+
`.GridSpec` instead). Likewise, the ``get_geometry``, ``change_geometry``,
13+
``update_params``, and ``figbox`` methods/attributes of `.SubplotDivider` have
14+
been deprecated, with similar replacements.
1215

1316
Axes constructor
1417
~~~~~~~~~~~~~~~~

lib/mpl_toolkits/axes_grid1/axes_divider.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,27 +347,33 @@ def __init__(self, fig, *args, horizontal=None, vertical=None,
347347
(2, 3, 4)).
348348
"""
349349
self.figure = fig
350-
self._subplotspec = SubplotSpec._from_subplot_args(fig, args)
351-
self.update_params() # sets self.figbox
352-
super().__init__(fig, pos=self.figbox.bounds,
350+
super().__init__(fig, [0, 0, 1, 1],
353351
horizontal=horizontal or [], vertical=vertical or [],
354352
aspect=aspect, anchor=anchor)
353+
self.set_subplotspec(SubplotSpec._from_subplot_args(fig, args))
355354

356355
def get_position(self):
357356
"""Return the bounds of the subplot box."""
358-
self.update_params() # update self.figbox
359-
return self.figbox.bounds
357+
return self.get_subplotspec().get_position(self.figure).bounds
360358

359+
@cbook.deprecated("3.4")
360+
@property
361+
def figbox(self):
362+
return self.get_subplotspec().get_position(self.figure)
363+
364+
@cbook.deprecated("3.4")
361365
def update_params(self):
362-
"""Update the subplot position from fig.subplotpars."""
363-
self.figbox = self.get_subplotspec().get_position(self.figure)
366+
pass
364367

368+
@cbook.deprecated(
369+
"3.4", alternative="get_subplotspec",
370+
addendum="(get_subplotspec returns a SubplotSpec instance.)")
365371
def get_geometry(self):
366372
"""Get the subplot geometry, e.g., (2, 2, 3)."""
367373
rows, cols, num1, num2 = self.get_subplotspec().get_geometry()
368374
return rows, cols, num1 + 1 # for compatibility
369375

370-
# COVERAGE NOTE: Never used internally or from examples
376+
@cbook.deprecated("3.4", alternative="set_subplotspec")
371377
def change_geometry(self, numrows, numcols, num):
372378
"""Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3)."""
373379
self._subplotspec = GridSpec(numrows, numcols)[num-1]
@@ -381,6 +387,7 @@ def get_subplotspec(self):
381387
def set_subplotspec(self, subplotspec):
382388
"""Set the SubplotSpec instance."""
383389
self._subplotspec = subplotspec
390+
self.set_position(subplotspec.get_position(self.figure))
384391

385392

386393
class AxesDivider(Divider):

0 commit comments

Comments
 (0)