Skip to content

Commit abd1f1a

Browse files
committed
Redupe parameters dealiasing for clarity.
The "canonical" property names for Axes3D were switched from xlim3d/ylim3d to xlim/ylim so that Axes3D can directly inherit the setters from 2D Axes.
1 parent 346b516 commit abd1f1a

File tree

5 files changed

+69
-78
lines changed

5 files changed

+69
-78
lines changed

lib/matplotlib/axes/_base.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -3691,9 +3691,17 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
36913691
36923692
>>> set_xlim(5000, 0)
36933693
"""
3694-
return self.xaxis._set_lim(
3695-
left, right, xmin, xmax, emit=emit, auto=auto,
3696-
names=("left", "right"))
3694+
if right is None and np.iterable(left):
3695+
left, right = left
3696+
if xmin is not None:
3697+
if left is not None:
3698+
raise TypeError("Cannot pass both 'left' and 'xmin'")
3699+
left = xmin
3700+
if xmax is not None:
3701+
if right is not None:
3702+
raise TypeError("Cannot pass both 'right' and 'xmax'")
3703+
right = xmax
3704+
return self.xaxis._set_lim(left, right, emit=emit, auto=auto)
36973705

36983706
get_xscale = _axis_method_wrapper("xaxis", "get_scale")
36993707

@@ -3955,9 +3963,17 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
39553963
39563964
>>> set_ylim(5000, 0)
39573965
"""
3958-
return self.yaxis._set_lim(
3959-
bottom, top, ymin, ymax, emit=emit, auto=auto,
3960-
names=("bottom", "top"))
3966+
if top is None and np.iterable(bottom):
3967+
bottom, top = bottom
3968+
if ymin is not None:
3969+
if bottom is not None:
3970+
raise TypeError("Cannot pass both 'bottom' and 'ymin'")
3971+
bottom = ymin
3972+
if ymax is not None:
3973+
if top is not None:
3974+
raise TypeError("Cannot pass both 'top' and 'ymax'")
3975+
top = ymax
3976+
return self.yaxis._set_lim(bottom, top, emit=emit, auto=auto)
39613977

39623978
get_yscale = _axis_method_wrapper("yaxis", "get_scale")
39633979

lib/matplotlib/axis.py

+19-35
Original file line numberDiff line numberDiff line change
@@ -1022,40 +1022,27 @@ def set_default_intervals(self):
10221022
# attribute, and the derived code below will check for that
10231023
# and use it if it's available (else just use 0..1)
10241024

1025-
def _set_lim(self, v0, v1, alt0=None, alt1=None, *,
1026-
emit=True, auto, names=("", "")):
1025+
def _set_lim(self, v0, v1, *, emit=True, auto):
10271026
"""
10281027
Set view limits.
10291028
10301029
This method is a helper for the Axes ``set_xlim``, ``set_ylim``, and
1031-
``set_zlim`` methods. This docstring uses names corresponding to
1032-
``set_xlim`` for simplicity.
1030+
``set_zlim`` methods.
10331031
1034-
*names* is the pair of the names of the first two parameters of the
1035-
Axes method (e.g., "left" and "right"). They are only used to generate
1036-
error messages; and can be empty if the limits are known to be valid.
1037-
1038-
Other parameters are directly forwarded from the Axes limits setter:
1039-
*v0*, *v1*, *alt0*, and *alt1* map to *left*, *right*, *xmin*, and
1040-
*xmax* respectively; *emit* and *auto* are used as is.
1032+
Parameters
1033+
----------
1034+
v0, v1 : float
1035+
The view limits. (Passing *v0* as a (low, high) pair is not
1036+
supported; normalization must occur in the Axes setters.)
1037+
emit : bool, default: True
1038+
Whether to notify observers of limit change.
1039+
auto : bool or None, default: False
1040+
Whether to turn on autoscaling of the x-axis. True turns on, False
1041+
turns off, None leaves unchanged.
10411042
"""
1042-
v0name, v1name = names # The value names.
10431043
name, = [name for name, axis in self.axes._get_axis_map().items()
10441044
if axis is self] # The axis name.
10451045

1046-
if v1 is None and np.iterable(v0):
1047-
v0, v1 = v0
1048-
if alt0 is not None:
1049-
if v0 is not None:
1050-
raise TypeError(
1051-
f"Cannot pass both {v0name!r} and '{name}lim'")
1052-
v0 = alt0
1053-
if alt1 is not None:
1054-
if v1 is not None:
1055-
raise TypeError(
1056-
f"Cannot pass both {v1name!r} and '{name}lim'")
1057-
v1 = alt1
1058-
10591046
self.axes._process_unit_info([(name, (v0, v1))], convert=False)
10601047
v0 = self.axes._validate_converted_limits(v0, self.convert_units)
10611048
v1 = self.axes._validate_converted_limits(v1, self.convert_units)
@@ -1074,23 +1061,20 @@ def _set_lim(self, v0, v1, alt0=None, alt1=None, *,
10741061
# so only grab the limits if we really need them.
10751062
old0, old1 = self.get_view_interval()
10761063
if v0 <= 0:
1077-
_api.warn_external(
1078-
f"Attempt to set non-positive {v0name} {name}lim on a "
1079-
f"log-scaled axis will be ignored.")
1064+
_api.warn_external(f"Attempt to set non-positive {name}lim on "
1065+
f"a log-scaled axis will be ignored.")
10801066
v0 = old0
10811067
if v1 <= 0:
1082-
_api.warn_external(
1083-
f"Attempt to set non-positive {v1name} {name}lim on a "
1084-
f"log-scaled axis will be ignored.")
1068+
_api.warn_external(f"Attempt to set non-positive {name}lim on "
1069+
f"a log-scaled axis will be ignored.")
10851070
v1 = old1
10861071
if v0 == v1:
10871072
_api.warn_external(
1088-
f"Attempting to set identical {v0name} == {v1name} == {v0} "
1073+
f"Attempting to set identical low and high {name}lims "
10891074
f"makes transformation singular; automatically expanding.")
1090-
reverse = v0 > v1
1075+
reverse = bool(v0 > v1) # explicit cast needed for python3.8+np.bool_.
10911076
v0, v1 = self.get_major_locator().nonsingular(v0, v1)
10921077
v0, v1 = self.limit_range_for_scale(v0, v1)
1093-
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
10941078
v0, v1 = sorted([v0, v1], reverse=bool(reverse))
10951079

10961080
self.set_view_interval(v0, v1, ignore=True)
@@ -1106,7 +1090,7 @@ def _set_lim(self, v0, v1, alt0=None, alt1=None, *,
11061090
for other in self.axes._shared_axes[name].get_siblings(self.axes):
11071091
if other is not self.axes:
11081092
other._get_axis_map()[name]._set_lim(
1109-
v0, v1, emit=False, auto=auto, names=names)
1093+
v0, v1, emit=False, auto=auto)
11101094
if other.figure != self.figure:
11111095
other.figure.canvas.draw_idle()
11121096

lib/matplotlib/tests/test_dates.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ def test_too_many_date_ticks(caplog):
182182
with pytest.warns(UserWarning) as rec:
183183
ax.set_xlim((t0, tf), auto=True)
184184
assert len(rec) == 1
185-
assert \
186-
'Attempting to set identical left == right' in str(rec[0].message)
185+
assert ('Attempting to set identical low and high xlims'
186+
in str(rec[0].message))
187187
ax.plot([], [])
188188
ax.xaxis.set_major_locator(mdates.DayLocator())
189189
v = ax.xaxis.get_major_locator()()

lib/matplotlib/tests/test_image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ def test_imshow_bignumbers_real():
977977
def test_empty_imshow(make_norm):
978978
fig, ax = plt.subplots()
979979
with pytest.warns(UserWarning,
980-
match="Attempting to set identical left == right"):
980+
match="Attempting to set identical low and high xlims"):
981981
im = ax.imshow([[]], norm=make_norm())
982982
im.set_extent([-5, 5, -5, 5])
983983
fig.canvas.draw()

lib/mpl_toolkits/mplot3d/axes3d.py

+25-34
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
@docstring.interpd
4444
@cbook._define_aliases({
45-
"xlim3d": ["xlim"], "ylim3d": ["ylim"], "zlim3d": ["zlim"]})
45+
"xlim": ["xlim3d"], "ylim": ["ylim3d"], "zlim": ["zlim3d"]})
4646
class Axes3D(Axes):
4747
"""
4848
3D Axes object.
@@ -659,48 +659,39 @@ def get_w_lims(self):
659659
minz, maxz = self.get_zlim3d()
660660
return minx, maxx, miny, maxy, minz, maxz
661661

662-
def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
663-
*, xmin=None, xmax=None):
664-
"""
665-
Set 3D x limits.
666-
667-
See `.Axes.set_xlim` for full documentation.
668-
"""
669-
return self.xaxis._set_lim(
670-
left, right, xmin, xmax, emit=emit, auto=auto,
671-
names=("left", "right"))
672-
673-
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
674-
*, ymin=None, ymax=None):
675-
"""
676-
Set 3D y limits.
677-
678-
See `.Axes.set_ylim` for full documentation.
679-
"""
680-
return self.yaxis._set_lim(
681-
bottom, top, ymin, ymax, emit=emit, auto=auto,
682-
names=("bottom", "top"))
683-
684-
def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
685-
*, zmin=None, zmax=None):
662+
# set_xlim, set_ylim are directly inherited from base Axes.
663+
def set_zlim(self, bottom=None, top=None, emit=True, auto=False,
664+
*, zmin=None, zmax=None):
686665
"""
687666
Set 3D z limits.
688667
689668
See `.Axes.set_ylim` for full documentation
690669
"""
691-
return self.zaxis._set_lim(
692-
bottom, top, zmin, zmax, emit=emit, auto=auto,
693-
names=("bottom", "top"))
694-
695-
def get_xlim3d(self):
670+
if top is None and np.iterable(bottom):
671+
bottom, top = bottom
672+
if zmin is not None:
673+
if bottom is not None:
674+
raise TypeError("Cannot pass both 'bottom' and 'zmin'")
675+
bottom = zmin
676+
if zmax is not None:
677+
if top is not None:
678+
raise TypeError("Cannot pass both 'top' and 'zmax'")
679+
top = zmax
680+
return self.zaxis._set_lim(bottom, top, emit=emit, auto=auto)
681+
682+
set_xlim3d = maxes.Axes.set_xlim
683+
set_ylim3d = maxes.Axes.set_ylim
684+
set_zlim3d = set_zlim
685+
686+
def get_xlim(self):
687+
# docstring inherited
696688
return tuple(self.xy_viewLim.intervalx)
697-
get_xlim3d.__doc__ = maxes.Axes.get_xlim.__doc__
698689

699-
def get_ylim3d(self):
690+
def get_ylim(self):
691+
# docstring inherited
700692
return tuple(self.xy_viewLim.intervaly)
701-
get_ylim3d.__doc__ = maxes.Axes.get_ylim.__doc__
702693

703-
def get_zlim3d(self):
694+
def get_zlim(self):
704695
"""Get 3D z limits."""
705696
return tuple(self.zz_viewLim.intervalx)
706697

0 commit comments

Comments
 (0)