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

Skip to content

Commit 6eeb9ba

Browse files
committed
Prepare axes_divider for simpler(?) indexing-based API.
See changelog note for motivation.
1 parent 178b46e commit 6eeb9ba

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
@@ -222,8 +222,16 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
222222
x0, y0 = x, y
223223

224224
if nx1 is None:
225+
_api.warn_deprecated(
226+
"3.5", message="Support for passing nx1=None to mean nx+1 is "
227+
"deprecated since %(since)s; in a future version, nx1=None "
228+
"will mean 'up to the last cell'.")
225229
nx1 = nx + 1
226230
if ny1 is None:
231+
_api.warn_deprecated(
232+
"3.5", message="Support for passing ny1=None to mean ny+1 is "
233+
"deprecated since %(since)s; in a future version, ny1=None "
234+
"will mean 'up to the last cell'.")
227235
ny1 = ny + 1
228236

229237
x1, w1 = x0 + ox[nx] / figW, (ox[nx1] - ox[nx]) / figW
@@ -245,7 +253,10 @@ def new_locator(self, nx, ny, nx1=None, ny1=None):
245253
ny, ny1 : int
246254
Same as *nx* and *nx1*, but for row positions.
247255
"""
248-
return AxesLocator(self, nx, ny, nx1, ny1)
256+
return AxesLocator(
257+
self, nx, ny,
258+
nx1 if nx1 is not None else nx + 1,
259+
ny1 if ny1 is not None else ny + 1)
249260

250261
def append_size(self, position, size):
251262
if position == "left":
@@ -275,9 +286,10 @@ def add_auto_adjustable_area(self, use_axes, pad=0.1, adjust_dirs=None):
275286

276287
class AxesLocator:
277288
"""
278-
A simple callable object, initialized with AxesDivider class,
279-
returns the position and size of the given cell.
289+
A callable object which returns the position and size of a given
290+
AxesDivider cell.
280291
"""
292+
281293
def __init__(self, axes_divider, nx, ny, nx1=None, ny1=None):
282294
"""
283295
Parameters
@@ -299,8 +311,16 @@ def __init__(self, axes_divider, nx, ny, nx1=None, ny1=None):
299311
self._nx, self._ny = nx - _xrefindex, ny - _yrefindex
300312

301313
if nx1 is None:
314+
_api.warn_deprecated(
315+
"3.5", message="Support for passing nx1=None to mean nx+1 is "
316+
"deprecated since %(since)s; in a future version, nx1=None "
317+
"will mean 'up to the last cell'.")
302318
nx1 = nx + 1
303319
if ny1 is None:
320+
_api.warn_deprecated(
321+
"3.5", message="Support for passing ny1=None to mean ny+1 is "
322+
"deprecated since %(since)s; in a future version, ny1=None "
323+
"will mean 'up to the last cell'.")
304324
ny1 = ny + 1
305325

306326
self._nx1 = nx1 - _xrefindex
@@ -629,7 +649,7 @@ def new_locator(self, nx, nx1=None):
629649
specified. Otherwise location of columns spanning between *nx*
630650
to *nx1* (but excluding *nx1*-th column) is specified.
631651
"""
632-
return AxesLocator(self, nx, 0, nx1, None)
652+
return AxesLocator(self, nx, 0, nx1 if nx1 is not None else nx + 1, 1)
633653

634654
def _locate(self, x, y, w, h,
635655
y_equivalent_sizes, x_appended_sizes,
@@ -666,6 +686,10 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
666686
y_equivalent_sizes, x_appended_sizes,
667687
figW, figH)
668688
if nx1 is None:
689+
_api.warn_deprecated(
690+
"3.5", message="Support for passing nx1=None to mean nx+1 is "
691+
"deprecated since %(since)s; in a future version, nx1=None "
692+
"will mean 'up to the last cell'.")
669693
nx1 = nx + 1
670694

671695
x1, w1 = x0 + ox[nx] / figW, (ox[nx1] - ox[nx]) / figW
@@ -691,7 +715,7 @@ def new_locator(self, ny, ny1=None):
691715
specified. Otherwise location of rows spanning between *ny*
692716
to *ny1* (but excluding *ny1*-th row) is specified.
693717
"""
694-
return AxesLocator(self, 0, ny, None, ny1)
718+
return AxesLocator(self, 0, ny, 1, ny1 if ny1 is not None else ny + 1)
695719

696720
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
697721
# docstring inherited
@@ -704,6 +728,10 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
704728
x_equivalent_sizes, y_appended_sizes,
705729
figH, figW)
706730
if ny1 is None:
731+
_api.warn_deprecated(
732+
"3.5", message="Support for passing ny1=None to mean ny+1 is "
733+
"deprecated since %(since)s; in a future version, ny1=None "
734+
"will mean 'up to the last cell'.")
707735
ny1 = ny + 1
708736

709737
x1, w1 = x0, ww

0 commit comments

Comments
 (0)