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

Skip to content

Commit 112c294

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 4bb6838 commit 112c294

File tree

3 files changed

+58
-70
lines changed

3 files changed

+58
-70
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 22 additions & 6 deletions
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

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,40 +1023,21 @@ def set_default_intervals(self):
10231023
# attribute, and the derived code below will check for that
10241024
# and use it if it's available (else just use 0..1)
10251025

1026-
def _set_lim(self, v0, v1, alt0=None, alt1=None, *,
1027-
emit=True, auto, names=("", "")):
1026+
def _set_lim(self, v0, v1, *, emit=True, auto):
10281027
"""
10291028
Set view limits.
10301029
10311030
This method is a helper for the Axes ``set_xlim``, ``set_ylim``, and
10321031
``set_zlim`` methods. This docstring uses names corresponding to
10331032
``set_xlim`` for simplicity.
10341033
1035-
*names* is the pair of the names of the first two parameters of the
1036-
Axes method (e.g., "left" and "right"). They are only used to generate
1037-
error messages; and can be empty if the limits are known to be valid.
1038-
1039-
Other parameters are directly forwarded from the Axes limits setter:
1040-
*v0*, *v1*, *alt0*, and *alt1* map to *left*, *right*, *xmin*, and
1041-
*xmax* respectively; *emit* and *auto* are used as is.
1034+
*v0* and *v1* are the view limits; they must be two scalars (passing a
1035+
*v0* as a (low, high) pair is not supported). *emit* and *auto* are
1036+
forwarded as-is from the Axes limits setter.
10421037
"""
1043-
v0name, v1name = names # The value names.
10441038
name, = [name for name, axis in self.axes._get_axis_map().items()
10451039
if axis is self] # The axis name.
10461040

1047-
if v1 is None and np.iterable(v0):
1048-
v0, v1 = v0
1049-
if alt0 is not None:
1050-
if v0 is not None:
1051-
raise TypeError(
1052-
f"Cannot pass both {v0name!r} and '{name}lim'")
1053-
v0 = alt0
1054-
if alt1 is not None:
1055-
if v1 is not None:
1056-
raise TypeError(
1057-
f"Cannot pass both {v1name!r} and '{name}lim'")
1058-
v1 = alt1
1059-
10601041
self.axes._process_unit_info([(name, (v0, v1))], convert=False)
10611042
v0 = self.axes._validate_converted_limits(v0, self.convert_units)
10621043
v1 = self.axes._validate_converted_limits(v1, self.convert_units)
@@ -1075,18 +1056,16 @@ def _set_lim(self, v0, v1, alt0=None, alt1=None, *,
10751056
# so only grab the limits if we really need them.
10761057
old0, old1 = self.get_view_interval()
10771058
if v0 <= 0:
1078-
_api.warn_external(
1079-
f"Attempt to set non-positive {v0name} {name}lim on a "
1080-
f"log-scaled axis will be ignored.")
1059+
_api.warn_external(f"Attempt to set non-positive {name}lim on "
1060+
f"a log-scaled axis will be ignored.")
10811061
v0 = old0
10821062
if v1 <= 0:
1083-
_api.warn_external(
1084-
f"Attempt to set non-positive {v1name} {name}lim on a "
1085-
f"log-scaled axis will be ignored.")
1063+
_api.warn_external(f"Attempt to set non-positive {name}lim on "
1064+
f"a log-scaled axis will be ignored.")
10861065
v1 = old1
10871066
if v0 == v1:
10881067
_api.warn_external(
1089-
f"Attempting to set identical {v0name} == {v1name} == {v0} "
1068+
f"Attempting to set identical low and high {name}lims "
10901069
f"makes transformation singular; automatically expanding.")
10911070
reverse = v0 > v1
10921071
v0, v1 = self.get_major_locator().nonsingular(v0, v1)
@@ -1107,7 +1086,7 @@ def _set_lim(self, v0, v1, alt0=None, alt1=None, *,
11071086
for other in self.axes._shared_axes[name].get_siblings(self.axes):
11081087
if other is not self.axes:
11091088
other._get_axis_map()[name]._set_lim(
1110-
v0, v1, emit=False, auto=auto, names=names)
1089+
v0, v1, emit=False, auto=auto)
11111090
if other.figure != self.figure:
11121091
other.figure.canvas.draw_idle()
11131092

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 26 additions & 33 deletions
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.
@@ -689,48 +689,41 @@ def get_w_lims(self):
689689
minz, maxz = self.get_zlim3d()
690690
return minx, maxx, miny, maxy, minz, maxz
691691

692-
def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
693-
*, xmin=None, xmax=None):
694-
"""
695-
Set 3D x limits.
696-
697-
See :meth:`matplotlib.axes.Axes.set_xlim` for full documentation.
698-
"""
699-
return self.xaxis._set_lim(
700-
left, right, xmin, xmax, emit=emit, auto=auto,
701-
names=("left", "right"))
702-
703-
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
704-
*, ymin=None, ymax=None):
705-
"""
706-
Set 3D y limits.
707-
708-
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation.
709-
"""
710-
return self.yaxis._set_lim(
711-
bottom, top, ymin, ymax, emit=emit, auto=auto,
712-
names=("bottom", "top"))
713-
714-
def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
692+
# set_xlim, set_ylim are directly inherited from base Axes.
693+
def set_zlim(self, bottom=None, top=None, emit=True, auto=False,
715694
*, zmin=None, zmax=None):
716695
"""
717696
Set 3D z limits.
718697
719698
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation
720699
"""
721-
return self.zaxis._set_lim(
722-
bottom, top, zmin, zmax, emit=emit, auto=auto,
723-
names=("bottom", "top"))
724-
725-
def get_xlim3d(self):
700+
if top is None and np.iterable(bottom):
701+
bottom, top = bottom
702+
if zmin is not None:
703+
if bottom is not None:
704+
raise TypeError("Cannot pass both 'bottom' and 'zmin'")
705+
bottom = zmin
706+
if zmax is not None:
707+
if top is not None:
708+
raise TypeError("Cannot pass both 'top' and 'zmax'")
709+
top = zmax
710+
return self.zaxis._set_lim(bottom, top, emit=emit, auto=auto)
711+
712+
set_xlim3d = maxes.Axes.set_xlim
713+
set_ylim3d = maxes.Axes.set_ylim
714+
set_zlim3d = set_zlim
715+
716+
def get_xlim(self):
726717
return tuple(self.xy_viewLim.intervalx)
727-
get_xlim3d.__doc__ = maxes.Axes.get_xlim.__doc__
728718

729-
def get_ylim3d(self):
719+
get_xlim.__doc__ = maxes.Axes.get_xlim.__doc__
720+
721+
def get_ylim(self):
730722
return tuple(self.xy_viewLim.intervaly)
731-
get_ylim3d.__doc__ = maxes.Axes.get_ylim.__doc__
732723

733-
def get_zlim3d(self):
724+
get_ylim.__doc__ = maxes.Axes.get_ylim.__doc__
725+
726+
def get_zlim(self):
734727
"""Get 3D z limits."""
735728
return tuple(self.zz_viewLim.intervalx)
736729

0 commit comments

Comments
 (0)