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

Skip to content

Commit 4a907b3

Browse files
committed
Clarify and check alternative names for axis limits
1 parent 3782de2 commit 4a907b3

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 24 additions & 16 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
@@ -3073,15 +3074,18 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
30733074
>>> set_xlim(5000, 0)
30743075
30753076
"""
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-
30833077
if right is None and iterable(left):
30843078
left, right = left
3079+
if xmin is not None:
3080+
if left is not None:
3081+
raise ValueError('Cannot use argument xmin=%r; would '
3082+
'override left=%r' % (xmin, left))
3083+
left = xmin
3084+
if xmax is not None:
3085+
if right is not None:
3086+
raise ValueError('Cannot use argument xmax=%r; would '
3087+
'override right=%r' % (xmax, right))
3088+
right = xmax
30853089

30863090
self._process_unit_info(xdata=(left, right))
30873091
left = self._validate_converted_limits(left, self.convert_xunits)
@@ -3346,7 +3350,8 @@ def get_ylim(self):
33463350
"""
33473351
return tuple(self.viewLim.intervaly)
33483352

3349-
def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
3353+
def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
3354+
*, ymin=None, ymax=None):
33503355
"""
33513356
Set the data limits for the y-axis
33523357
@@ -3402,15 +3407,18 @@ 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+
raise ValueError('Cannot use argument ymin=%r; would '
3415+
'override bottom=%r' % (ymin, bottom))
3416+
bottom = ymin
3417+
if ymax is not None:
3418+
if top is not None:
3419+
raise ValueError('Cannot use argument ymax=%r; would '
3420+
'override top=%r' % (ymax, top))
3421+
top = ymax
34143422

34153423
bottom = self._validate_converted_limits(bottom, self.convert_yunits)
34163424
top = self._validate_converted_limits(top, self.convert_yunits)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -610,22 +610,26 @@ 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+
raise ValueError('Cannot use argument xmin=%r; would '
626+
'override left=%r' % (xmin, left))
627+
left = xmin
628+
if xmax is not None:
629+
if right is not None:
630+
raise ValueError('Cannot use argument xmax=%r; would '
631+
'override right=%r' % (xmax, right))
632+
right = xmax
629633

630634
self._process_unit_info(xdata=(left, right))
631635
left = self._validate_converted_limits(left, self.convert_xunits)
@@ -662,22 +666,26 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
662666
return left, right
663667
set_xlim = set_xlim3d
664668

665-
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
669+
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
670+
*, ymin=None, ymax=None):
666671
"""
667672
Set 3D y limits.
668673
669674
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation.
670675
671676
"""
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-
679677
if top is None and cbook.iterable(bottom):
680678
bottom, top = bottom
679+
if ymin is not None:
680+
if bottom is not None:
681+
raise ValueError('Cannot use argument ymin=%r; would '
682+
'override bottom=%r' % (ymin, bottom))
683+
bottom = ymin
684+
if ymax is not None:
685+
if top is not None:
686+
raise ValueError('Cannot use argument ymax=%r; would '
687+
'override top=%r' % (ymax, top))
688+
top = ymax
681689

682690
self._process_unit_info(ydata=(bottom, top))
683691
bottom = self._validate_converted_limits(bottom, self.convert_yunits)
@@ -714,22 +722,26 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
714722
return bottom, top
715723
set_ylim = set_ylim3d
716724

717-
def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
725+
def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
726+
*, zmin=None, zmax=None):
718727
"""
719728
Set 3D z limits.
720729
721730
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation
722731
723732
"""
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-
731733
if top is None and cbook.iterable(bottom):
732734
bottom, top = bottom
735+
if zmin is not None:
736+
if bottom is not None:
737+
raise ValueError('Cannot use argument zmin=%r; would '
738+
'override bottom=%r' % (zmin, bottom))
739+
bottom = zmin
740+
if zmax is not None:
741+
if top is not None:
742+
raise ValueError('Cannot use argument zmax=%r; would '
743+
'override top=%r' % (zmax, top))
744+
top = zmax
733745

734746
self._process_unit_info(zdata=(bottom, top))
735747
bottom = self._validate_converted_limits(bottom, self.convert_zunits)

0 commit comments

Comments
 (0)