Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 09991e6

Browse filesBrowse files
committed
Clarify and check alternative names for axis limits
1 parent 6be9c9f commit 09991e6
Copy full SHA for 09991e6

File tree

Expand file treeCollapse file tree

3 files changed

+96
-48
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+96
-48
lines changed
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Different exception types for undocumented options
2+
--------------------------------------------------
3+
4+
- Passing the undocumented ``xmin`` or ``xmax`` arguments to
5+
:meth:`~matplotlib.axes.Axes.set_xlim` would silently override the ``left``
6+
and ``right`` arguments. :meth:`~matplotlib.axes.Axes.set_ylim` and the
7+
3D equivalents (e.g. :meth:`~mpl_toolkits.axes.Axes3D.set_zlim3d`) had a
8+
corresponding problem.
9+
The ``_min`` and ``_max`` arguments are now deprecated, and a ``TypeError``
10+
will be raised if they would override the earlier limit arguments.

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+44-24Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,7 +3028,8 @@ def _validate_converted_limits(self, limit, convert):
30283028
raise ValueError("Axis limits cannot be NaN or Inf")
30293029
return converted_limit
30303030

3031-
def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
3031+
def set_xlim(self, left=None, right=None, emit=True, auto=False,
3032+
*, xmin=None, xmax=None):
30323033
"""
30333034
Set the data limits for the x-axis
30343035
@@ -3039,6 +3040,9 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
30393040
left : scalar, optional
30403041
The left xlim (default: None, which leaves the left limit
30413042
unchanged).
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).
30423046
30433047
right : scalar, optional
30443048
The right xlim (default: None, which leaves the right limit
@@ -3051,10 +3055,11 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
30513055
Whether to turn on autoscaling of the x-axis. True turns on,
30523056
False turns off (default action), None leaves unchanged.
30533057
3054-
xlimits : tuple, optional
3055-
The left and right xlims may be passed as the tuple
3056-
(`left`, `right`) as the first positional argument (or as
3057-
the `left` keyword argument).
3058+
xmin, xmax : scalar, optional
3059+
These arguments are deprecated and will be removed in a future
3060+
version. They are equivalent to left and right respectively,
3061+
and it is an error to pass both `xmin` and `left` or
3062+
`xmax` and `right`.
30583063
30593064
Returns
30603065
-------
@@ -3085,15 +3090,20 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
30853090
>>> set_xlim(5000, 0)
30863091
30873092
"""
3088-
if 'xmin' in kw:
3089-
left = kw.pop('xmin')
3090-
if 'xmax' in kw:
3091-
right = kw.pop('xmax')
3092-
if kw:
3093-
raise ValueError("unrecognized kwargs: %s" % list(kw))
3094-
30953093
if right is None and iterable(left):
30963094
left, right = left
3095+
if xmin is not None:
3096+
cbook.warn_deprecated('3.0', name='`xmin`',
3097+
alternative='`left`', obj_type='argument')
3098+
if left is not None:
3099+
raise TypeError('Cannot pass both `xmin` and `left`')
3100+
left = xmin
3101+
if xmax is not None:
3102+
cbook.warn_deprecated('3.0', name='`xmax`',
3103+
alternative='`right`', obj_type='argument')
3104+
if right is not None:
3105+
raise TypeError('Cannot pass both `xmax` and `right`')
3106+
right = xmax
30973107

30983108
self._process_unit_info(xdata=(left, right))
30993109
left = self._validate_converted_limits(left, self.convert_xunits)
@@ -3358,7 +3368,8 @@ def get_ylim(self):
33583368
"""
33593369
return tuple(self.viewLim.intervaly)
33603370

3361-
def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
3371+
def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
3372+
*, ymin=None, ymax=None):
33623373
"""
33633374
Set the data limits for the y-axis
33643375
@@ -3369,6 +3380,9 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
33693380
bottom : scalar, optional
33703381
The bottom ylim (default: None, which leaves the bottom
33713382
limit unchanged).
3383+
The bottom and top ylims may be passed as the tuple
3384+
(`bottom`, `top`) as the first positional argument (or as
3385+
the `bottom` keyword argument).
33723386
33733387
top : scalar, optional
33743388
The top ylim (default: None, which leaves the top limit
@@ -3381,10 +3395,11 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
33813395
Whether to turn on autoscaling of the y-axis. True turns on,
33823396
False turns off (default action), None leaves unchanged.
33833397
3384-
ylimits : tuple, optional
3385-
The bottom and top yxlims may be passed as the tuple
3386-
(`bottom`, `top`) as the first positional argument (or as
3387-
the `bottom` keyword argument).
3398+
ymin, ymax : scalar, optional
3399+
These arguments are deprecated and will be removed in a future
3400+
version. They are equivalent to bottom and top respectively,
3401+
and it is an error to pass both `xmin` and `bottom` or
3402+
`xmax` and `top`.
33883403
33893404
Returns
33903405
-------
@@ -3414,15 +3429,20 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
34143429
34153430
>>> set_ylim(5000, 0)
34163431
"""
3417-
if 'ymin' in kw:
3418-
bottom = kw.pop('ymin')
3419-
if 'ymax' in kw:
3420-
top = kw.pop('ymax')
3421-
if kw:
3422-
raise ValueError("unrecognized kwargs: %s" % list(kw))
3423-
34243432
if top is None and iterable(bottom):
34253433
bottom, top = bottom
3434+
if ymin is not None:
3435+
cbook.warn_deprecated('3.0', name='`ymin`',
3436+
alternative='`bottom`', obj_type='argument')
3437+
if bottom is not None:
3438+
raise TypeError('Cannot pass both `ymin` and `bottom`')
3439+
bottom = ymin
3440+
if ymax is not None:
3441+
cbook.warn_deprecated('3.0', name='`ymax`',
3442+
alternative='`top`', obj_type='argument')
3443+
if top is not None:
3444+
raise TypeError('Cannot pass both `ymax` and `top`')
3445+
top = ymax
34263446

34273447
bottom = self._validate_converted_limits(bottom, self.convert_yunits)
34283448
top = self._validate_converted_limits(top, self.convert_yunits)

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+42-24Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -603,22 +603,28 @@ def _determine_lims(self, xmin=None, xmax=None, *args, **kwargs):
603603
xmax += 0.05
604604
return (xmin, xmax)
605605

606-
def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
606+
def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
607+
*, xmin=None, xmax=None):
607608
"""
608609
Set 3D x limits.
609610
610611
See :meth:`matplotlib.axes.Axes.set_xlim` for full documentation.
611612
612613
"""
613-
if 'xmin' in kw:
614-
left = kw.pop('xmin')
615-
if 'xmax' in kw:
616-
right = kw.pop('xmax')
617-
if kw:
618-
raise ValueError("unrecognized kwargs: %s" % list(kw))
619-
620614
if right is None and cbook.iterable(left):
621615
left, right = left
616+
if xmin is not None:
617+
cbook.warn_deprecated('3.0', name='`xmin`',
618+
alternative='`left`', obj_type='argument')
619+
if left is not None:
620+
raise TypeError('Cannot pass both `xmin` and `left`')
621+
left = xmin
622+
if xmax is not None:
623+
cbook.warn_deprecated('3.0', name='`xmax`',
624+
alternative='`right`', obj_type='argument')
625+
if right is not None:
626+
raise TypeError('Cannot pass both `xmax` and `right`')
627+
right = xmax
622628

623629
self._process_unit_info(xdata=(left, right))
624630
left = self._validate_converted_limits(left, self.convert_xunits)
@@ -655,22 +661,28 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
655661
return left, right
656662
set_xlim = set_xlim3d
657663

658-
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
664+
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
665+
*, ymin=None, ymax=None):
659666
"""
660667
Set 3D y limits.
661668
662669
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation.
663670
664671
"""
665-
if 'ymin' in kw:
666-
bottom = kw.pop('ymin')
667-
if 'ymax' in kw:
668-
top = kw.pop('ymax')
669-
if kw:
670-
raise ValueError("unrecognized kwargs: %s" % list(kw))
671-
672672
if top is None and cbook.iterable(bottom):
673673
bottom, top = bottom
674+
if ymin is not None:
675+
cbook.warn_deprecated('3.0', name='`ymin`',
676+
alternative='`bottom`', obj_type='argument')
677+
if bottom is not None:
678+
raise TypeError('Cannot pass both `ymin` and `bottom`')
679+
bottom = ymin
680+
if ymax is not None:
681+
cbook.warn_deprecated('3.0', name='`ymax`',
682+
alternative='`top`', obj_type='argument')
683+
if top is not None:
684+
raise TypeError('Cannot pass both `ymax` and `top`')
685+
top = ymax
674686

675687
self._process_unit_info(ydata=(bottom, top))
676688
bottom = self._validate_converted_limits(bottom, self.convert_yunits)
@@ -707,22 +719,28 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
707719
return bottom, top
708720
set_ylim = set_ylim3d
709721

710-
def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
722+
def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
723+
*, zmin=None, zmax=None):
711724
"""
712725
Set 3D z limits.
713726
714727
See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation
715728
716729
"""
717-
if 'zmin' in kw:
718-
bottom = kw.pop('zmin')
719-
if 'zmax' in kw:
720-
top = kw.pop('zmax')
721-
if kw:
722-
raise ValueError("unrecognized kwargs: %s" % list(kw))
723-
724730
if top is None and cbook.iterable(bottom):
725731
bottom, top = bottom
732+
if zmin is not None:
733+
cbook.warn_deprecated('3.0', name='`zmin`',
734+
alternative='`bottom`', obj_type='argument')
735+
if bottom is not None:
736+
raise TypeError('Cannot pass both `zmin` and `bottom`')
737+
bottom = zmin
738+
if zmax is not None:
739+
cbook.warn_deprecated('3.0', name='`zmax`',
740+
alternative='`top`', obj_type='argument')
741+
if top is not None:
742+
raise TypeError('Cannot pass both `zmax` and `top`')
743+
top = zmax
726744

727745
self._process_unit_info(zdata=(bottom, top))
728746
bottom = self._validate_converted_limits(bottom, self.convert_zunits)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.