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

Skip to content

Commit 2a26787

Browse files
authored
Merge pull request #20079 from anntzer/nxy1none
Prepare axes_divider for simpler(?) indexing-based API.
2 parents 9ca2a29 + 6eeb9ba commit 2a26787

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Support for ``nx1 = None`` or ``ny1 = None`` in ``AxesLocator`` and ``Divider.locate``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
In :mod:`.axes_grid1.axes_divider`, various internal APIs will stop supporting
5+
passing ``nx1 = None`` or ``ny1 = None`` to mean ``nx + 1`` or ``ny + 1``, in
6+
preparation for a possible future API which allows indexing and slicing of
7+
dividers (possibly ``divider[a:b] == divider.new_locator(a, b)``, but also
8+
``divider[a:] == divider.new_locator(a, <end>)``). The user-facing
9+
`.Divider.new_locator` API is unaffected -- it correctly normalizes ``nx1 = None``
10+
and ``ny1 = None`` as needed.

lib/mpl_toolkits/axes_grid1/axes_divider.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,16 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
214214
x0, y0 = x, y
215215

216216
if nx1 is None:
217+
_api.warn_deprecated(
218+
"3.5", message="Support for passing nx1=None to mean nx+1 is "
219+
"deprecated since %(since)s; in a future version, nx1=None "
220+
"will mean 'up to the last cell'.")
217221
nx1 = nx + 1
218222
if ny1 is None:
223+
_api.warn_deprecated(
224+
"3.5", message="Support for passing ny1=None to mean ny+1 is "
225+
"deprecated since %(since)s; in a future version, ny1=None "
226+
"will mean 'up to the last cell'.")
219227
ny1 = ny + 1
220228

221229
x1, w1 = x0 + ox[nx] / fig_w, (ox[nx1] - ox[nx]) / fig_w
@@ -237,7 +245,10 @@ def new_locator(self, nx, ny, nx1=None, ny1=None):
237245
ny, ny1 : int
238246
Same as *nx* and *nx1*, but for row positions.
239247
"""
240-
return AxesLocator(self, nx, ny, nx1, ny1)
248+
return AxesLocator(
249+
self, nx, ny,
250+
nx1 if nx1 is not None else nx + 1,
251+
ny1 if ny1 is not None else ny + 1)
241252

242253
def append_size(self, position, size):
243254
if position == "left":
@@ -267,9 +278,10 @@ def add_auto_adjustable_area(self, use_axes, pad=0.1, adjust_dirs=None):
267278

268279
class AxesLocator:
269280
"""
270-
A simple callable object, initialized with AxesDivider class,
271-
returns the position and size of the given cell.
281+
A callable object which returns the position and size of a given
282+
AxesDivider cell.
272283
"""
284+
273285
def __init__(self, axes_divider, nx, ny, nx1=None, ny1=None):
274286
"""
275287
Parameters
@@ -291,8 +303,16 @@ def __init__(self, axes_divider, nx, ny, nx1=None, ny1=None):
291303
self._nx, self._ny = nx - _xrefindex, ny - _yrefindex
292304

293305
if nx1 is None:
306+
_api.warn_deprecated(
307+
"3.5", message="Support for passing nx1=None to mean nx+1 is "
308+
"deprecated since %(since)s; in a future version, nx1=None "
309+
"will mean 'up to the last cell'.")
294310
nx1 = nx + 1
295311
if ny1 is None:
312+
_api.warn_deprecated(
313+
"3.5", message="Support for passing ny1=None to mean ny+1 is "
314+
"deprecated since %(since)s; in a future version, ny1=None "
315+
"will mean 'up to the last cell'.")
296316
ny1 = ny + 1
297317

298318
self._nx1 = nx1 - _xrefindex
@@ -645,7 +665,7 @@ def new_locator(self, nx, nx1=None):
645665
specified. Otherwise location of columns spanning between *nx*
646666
to *nx1* (but excluding *nx1*-th column) is specified.
647667
"""
648-
return AxesLocator(self, nx, 0, nx1, None)
668+
return AxesLocator(self, nx, 0, nx1 if nx1 is not None else nx + 1, 1)
649669

650670
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
651671
# docstring inherited
@@ -656,6 +676,10 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
656676
x0, y0, ox, hh = _locate(
657677
x, y, w, h, summed_ws, equal_hs, fig_w, fig_h, self.get_anchor())
658678
if nx1 is None:
679+
_api.warn_deprecated(
680+
"3.5", message="Support for passing nx1=None to mean nx+1 is "
681+
"deprecated since %(since)s; in a future version, nx1=None "
682+
"will mean 'up to the last cell'.")
659683
nx1 = nx + 1
660684
x1, w1 = x0 + ox[nx] / fig_w, (ox[nx1] - ox[nx]) / fig_w
661685
y1, h1 = y0, hh
@@ -680,7 +704,7 @@ def new_locator(self, ny, ny1=None):
680704
specified. Otherwise location of rows spanning between *ny*
681705
to *ny1* (but excluding *ny1*-th row) is specified.
682706
"""
683-
return AxesLocator(self, 0, ny, None, ny1)
707+
return AxesLocator(self, 0, ny, 1, ny1 if ny1 is not None else ny + 1)
684708

685709
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
686710
# docstring inherited
@@ -691,6 +715,10 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
691715
y0, x0, oy, ww = _locate(
692716
y, x, h, w, summed_hs, equal_ws, fig_h, fig_w, self.get_anchor())
693717
if ny1 is None:
718+
_api.warn_deprecated(
719+
"3.5", message="Support for passing ny1=None to mean ny+1 is "
720+
"deprecated since %(since)s; in a future version, ny1=None "
721+
"will mean 'up to the last cell'.")
694722
ny1 = ny + 1
695723
x1, w1 = x0, ww
696724
y1, h1 = y0 + oy[ny] / fig_h, (oy[ny1] - oy[ny]) / fig_h

0 commit comments

Comments
 (0)