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

Skip to content

Commit 0a8878b

Browse files
committed
Clarify and check alternative names for axis limits
1 parent 48adfa1 commit 0a8878b

File tree

2 files changed

+60
-48
lines changed

2 files changed

+60
-48
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,7 +3016,8 @@ def _validate_converted_limits(self, limit, convert):
30163016
raise ValueError("Axis limits cannot be NaN or Inf")
30173017
return converted_limit
30183018

3019-
def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
3019+
def set_xlim(self, left=None, right=None, emit=True, auto=False,
3020+
*, xmin=None, xmax=None):
30203021
"""
30213022
Set the data limits for the x-axis
30223023
@@ -3027,6 +3028,9 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
30273028
left : scalar, optional
30283029
The left xlim (default: None, which leaves the left limit
30293030
unchanged).
3031+
The left and right xlims may be passed as the tuple
3032+
(`left`, `right`) as the first positional argument (or as
3033+
the `left` keyword argument).
30303034
30313035
right : scalar, optional
30323036
The right xlim (default: None, which leaves the right limit
@@ -3039,10 +3043,8 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
30393043
Whether to turn on autoscaling of the x-axis. True turns on,
30403044
False turns off (default action), None leaves unchanged.
30413045
3042-
xlimits : tuple, optional
3043-
The left and right xlims may be passed as the tuple
3044-
(`left`, `right`) as the first positional argument (or as
3045-
the `left` keyword argument).
3046+
ymin, ymax : scalar, optional
3047+
If passed, these arguments override bottom and top respectively.
30463048
30473049
Returns
30483050
-------
@@ -3073,15 +3075,16 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
30733075
>>> set_xlim(5000, 0)
30743076
30753077
"""
3076-
if 'xmin' in kw:
3077-
left = kw.pop('xmin')
3078-
if 'xmax' in kw:
3079-
right = kw.pop('xmax')
3080-
if kw:
3081-
raise ValueError("unrecognized kwargs: %s" % list(kw))
3082-
30833078
if right is None and iterable(left):
30843079
left, right = left
3080+
if xmin is not None:
3081+
if left is not None:
3082+
warnings.warn('xmin=%r overrides left=%r' % (xmin, left))
3083+
left = xmin
3084+
if xmax is not None:
3085+
if right is not None:
3086+
warnings.warn('xmax=%r overrides right=%r' % (xmax, right))
3087+
right = xmax
30853088

30863089
self._process_unit_info(xdata=(left, right))
30873090
left = self._validate_converted_limits(left, self.convert_xunits)
@@ -3346,7 +3349,8 @@ def get_ylim(self):
33463349
"""
33473350
return tuple(self.viewLim.intervaly)
33483351

3349-
def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
3352+
def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
3353+
*, ymin=None, ymax=None):
33503354
"""
33513355
Set the data limits for the y-axis
33523356
@@ -3357,6 +3361,9 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
33573361
bottom : scalar, optional
33583362
The bottom ylim (default: None, which leaves the bottom
33593363
limit unchanged).
3364+
The bottom and top yxlims may be passed as the tuple
3365+
(`bottom`, `top`) as the first positional argument (or as
3366+
the `bottom` keyword argument).
33603367
33613368
top : scalar, optional
33623369
The top ylim (default: None, which leaves the top limit
@@ -3369,10 +3376,8 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
33693376
Whether to turn on autoscaling of the y-axis. True turns on,
33703377
False turns off (default action), None leaves unchanged.
33713378
3372-
ylimits : tuple, optional
3373-
The bottom and top yxlims may be passed as the tuple
3374-
(`bottom`, `top`) as the first positional argument (or as
3375-
the `bottom` keyword argument).
3379+
ymin, ymax : scalar, optional
3380+
If passed, these arguments override bottom and top respectively.
33763381
33773382
Returns
33783383
-------
@@ -3402,15 +3407,16 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
34023407
34033408
>>> set_ylim(5000, 0)
34043409
"""
3405-
if 'ymin' in kw:
3406-
bottom = kw.pop('ymin')
3407-
if 'ymax' in kw:
3408-
top = kw.pop('ymax')
3409-
if kw:
3410-
raise ValueError("unrecognized kwargs: %s" % list(kw))
3411-
34123410
if top is None and iterable(bottom):
34133411
bottom, top = bottom
3412+
if ymin is not None:
3413+
if bottom is not None:
3414+
warnings.warn('ymin=%r overrides bottom=%r' % (ymin, bottom))
3415+
bottom = ymin
3416+
if ymax is not None:
3417+
if top is not None:
3418+
warnings.warn('ymax=%r overrides top=%r' % (ymax, top))
3419+
top = ymax
34143420

34153421
bottom = self._validate_converted_limits(bottom, self.convert_yunits)
34163422
top = self._validate_converted_limits(top, self.convert_yunits)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -610,22 +610,24 @@ def _determine_lims(self, xmin=None, xmax=None, *args, **kwargs):
610610
xmax += 0.05
611611
return (xmin, xmax)
612612

613-
def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
613+
def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
614+
*, xmin=None, xmax=None):
614615
"""
615616
Set 3D x limits.
616617
617618
See :meth:`matplotlib.axes.Axes.set_xlim` for full documentation.
618619
619620
"""
620-
if 'xmin' in kw:
621-
left = kw.pop('xmin')
622-
if 'xmax' in kw:
623-
right = kw.pop('xmax')
624-
if kw:
625-
raise ValueError("unrecognized kwargs: %s" % list(kw))
626-
627621
if right is None and cbook.iterable(left):
628622
left, right = left
623+
if xmin is not None:
624+
if left is not None:
625+
warnings.warn('xmin=%r overrides left=%r' % (xmin, left))
626+
left = xmin
627+
if xmax is not None:
628+
if right is not None:
629+
warnings.warn('xmax=%r overrides right=%r' % (xmax, right))
630+
right = xmax
629631

630632
self._process_unit_info(xdata=(left, right))
631633
left = self._validate_converted_limits(left, self.convert_xunits)
@@ -662,22 +664,24 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
662664
return left, right
663665
set_xlim = set_xlim3d
664666

665-
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
667+
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
668+
*, ymin=None, ymax=None):
666669
"""
667670
Set 3D y limits.
668671
669672
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation.
670673
671674
"""
672-
if 'ymin' in kw:
673-
bottom = kw.pop('ymin')
674-
if 'ymax' in kw:
675-
top = kw.pop('ymax')
676-
if kw:
677-
raise ValueError("unrecognized kwargs: %s" % list(kw))
678-
679675
if top is None and cbook.iterable(bottom):
680676
bottom, top = bottom
677+
if ymin is not None:
678+
if bottom is not None:
679+
warnings.warn('ymin=%r overrides bottom=%r' % (ymin, bottom))
680+
bottom = ymin
681+
if ymax is not None:
682+
if top is not None:
683+
warnings.warn('ymax=%r overrides top=%r' % (ymax, top))
684+
top = ymax
681685

682686
self._process_unit_info(ydata=(bottom, top))
683687
bottom = self._validate_converted_limits(bottom, self.convert_yunits)
@@ -714,22 +718,24 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
714718
return bottom, top
715719
set_ylim = set_ylim3d
716720

717-
def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
721+
def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
722+
*, zmin=None, zmax=None):
718723
"""
719724
Set 3D z limits.
720725
721726
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation
722727
723728
"""
724-
if 'zmin' in kw:
725-
bottom = kw.pop('zmin')
726-
if 'zmax' in kw:
727-
top = kw.pop('zmax')
728-
if kw:
729-
raise ValueError("unrecognized kwargs: %s" % list(kw))
730-
731729
if top is None and cbook.iterable(bottom):
732730
bottom, top = bottom
731+
if zmin is not None:
732+
if bottom is not None:
733+
warnings.warn('zmin=%r overrides bottom=%r' % (zmin, bottom))
734+
bottom = zmin
735+
if zmax is not None:
736+
if top is not None:
737+
warnings.warn('zmax=%r overrides top=%r' % (zmax, top))
738+
top = zmax
733739

734740
self._process_unit_info(zdata=(bottom, top))
735741
bottom = self._validate_converted_limits(bottom, self.convert_zunits)

0 commit comments

Comments
 (0)