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

Skip to content

Commit 8d69190

Browse files
committed
Deprecate nth_coord parameter from FixedAxisArtistHelper.new_fixed_axis.
FixedAxisArtistHelpers place an axis on either the bottom, top, left, or right of an axis per (`loc`); we already infer whether it's an x-axis or a y-axis (`nth_coord`) from that and error out if there's a mismatch, so we may just as well delete the nth_coord parameter (which was already optional to start with). While at it, also expire deprecation for passing inconsistent nth_coord and loc.
1 parent a99673c commit 8d69190

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*nth_coord* parameter to axisartist helpers for fixed axis
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Helper APIs in `.axisartist` for generating a "fixed" axis on rectilinear axes
4+
(`.FixedAxisArtistHelperRectilinear`) no longer take a *nth_coord* parameter,
5+
as that parameter is entirely inferred from the (required) *loc* parameter and
6+
having inconsistent *nth_coord* and *loc* is an error.
7+
8+
For curvilinear axes, the *nth_coord* parameter remains supported (it affects
9+
the *ticks*, not the axis position itself), but that parameter will become
10+
keyword-only, for consistency with the rectilinear case.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Inconsistent *nth_coord* and *loc* passed to ``_FixedAxisArtistHelperBase``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The value of the *nth_coord* parameter of ``_FixedAxisArtistHelperBase`` and
4+
its subclasses is now inferred from the value of *loc*; passing inconsistent
5+
values (e.g., requesting a "top y axis" or a "left x axis") has no more effect.

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,11 @@ class _FixedAxisArtistHelperBase(_AxisArtistHelperBase):
116116
lambda self: {"left": (0, 0), "right": (1, 0),
117117
"bottom": (0, 0), "top": (0, 1)}[self._loc]))
118118

119+
@_api.delete_parameter("3.9", "nth_coord")
119120
def __init__(self, loc, nth_coord=None):
120121
"""``nth_coord = 0``: x-axis; ``nth_coord = 1``: y-axis."""
121-
self.nth_coord = (
122-
nth_coord if nth_coord is not None else
123-
_api.check_getitem(
124-
{"bottom": 0, "top": 0, "left": 1, "right": 1}, loc=loc))
125-
if (nth_coord == 0 and loc not in ["left", "right"]
126-
or nth_coord == 1 and loc not in ["bottom", "top"]):
127-
_api.warn_deprecated(
128-
"3.7", message=f"{loc=!r} is incompatible with "
129-
"{nth_coord=}; support is deprecated since %(since)s")
122+
self.nth_coord = _api.check_getitem(
123+
{"bottom": 0, "top": 0, "left": 1, "right": 1}, loc=loc)
130124
self._loc = loc
131125
self._pos = {"bottom": 0, "top": 1, "left": 0, "right": 1}[loc]
132126
super().__init__()
@@ -184,12 +178,13 @@ def get_line(self, axes):
184178

185179
class FixedAxisArtistHelperRectilinear(_FixedAxisArtistHelperBase):
186180

181+
@_api.delete_parameter("3.9", "nth_coord")
187182
def __init__(self, axes, loc, nth_coord=None):
188183
"""
189184
nth_coord = along which coordinate value varies
190185
in 2D, nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
191186
"""
192-
super().__init__(loc, nth_coord)
187+
super().__init__(loc)
193188
self.axis = [axes.xaxis, axes.yaxis][self.nth_coord]
194189

195190
# TICK
@@ -333,6 +328,8 @@ def __init__(self, axes):
333328
super().__init__()
334329
self.axes = axes
335330

331+
@_api.delete_parameter(
332+
"3.9", "nth_coord", addendum="'nth_coord' is now inferred from 'loc'.")
336333
def new_fixed_axis(self, loc,
337334
nth_coord=None,
338335
axis_direction=None,
@@ -345,8 +342,7 @@ def new_fixed_axis(self, loc,
345342
axes = self.axes
346343
if axis_direction is None:
347344
axis_direction = loc
348-
349-
helper = FixedAxisArtistHelperRectilinear(axes, loc, nth_coord)
345+
helper = FixedAxisArtistHelperRectilinear(axes, loc)
350346
axisline = AxisArtist(axes, helper, offset=offset,
351347
axis_direction=axis_direction)
352348
return axisline
@@ -359,7 +355,6 @@ def new_floating_axis(self, nth_coord, value,
359355
_api.warn_external(
360356
"'new_floating_axis' explicitly requires the axes keyword.")
361357
axes = self.axes
362-
363358
helper = FloatingAxisArtistHelperRectilinear(
364359
axes, nth_coord, value, axis_direction)
365360
axisline = AxisArtist(axes, helper, axis_direction=axis_direction)
@@ -494,21 +489,11 @@ def get_children(self):
494489
return children
495490

496491
def new_fixed_axis(self, loc, offset=None):
497-
gh = self.get_grid_helper()
498-
axis = gh.new_fixed_axis(loc,
499-
nth_coord=None,
500-
axis_direction=None,
501-
offset=offset,
502-
axes=self,
503-
)
504-
return axis
492+
return self.get_grid_helper().new_fixed_axis(loc, offset=offset, axes=self)
505493

506494
def new_floating_axis(self, nth_coord, value, axis_direction="bottom"):
507-
gh = self.get_grid_helper()
508-
axis = gh.new_floating_axis(nth_coord, value,
509-
axis_direction=axis_direction,
510-
axes=self)
511-
return axis
495+
return self.get_grid_helper().new_floating_axis(
496+
nth_coord, value, axis_direction=axis_direction, axes=self)
512497

513498

514499
class AxesZero(Axes):

lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99

1010
import matplotlib as mpl
11+
from matplotlib import _api
1112
from matplotlib.path import Path
1213
from matplotlib.transforms import Affine2D, IdentityTransform
1314
from .axislines import (
@@ -270,6 +271,7 @@ def update_grid_finder(self, aux_trans=None, **kwargs):
270271
self.grid_finder.update(**kwargs)
271272
self._old_limits = None # Force revalidation.
272273

274+
@_api.make_keyword_only("3.9", "nth_coord")
273275
def new_fixed_axis(self, loc,
274276
nth_coord=None,
275277
axis_direction=None,

0 commit comments

Comments
 (0)