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

Skip to content

Commit d0e746b

Browse files
committed
Implement deprecation, error for e.g. left and xmin
1 parent 42b4aaa commit d0e746b

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

doc/api/next_api_changes/2018-04-22-ZHD.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ Different exception types for undocumented options
44
- Passing ``style='comma'`` to :meth:`~matplotlib.axes.Axes.ticklabel_format`
55
was never supported. It now raises ``ValueError`` like all other
66
unsupported styles, rather than ``NotImplementedError``.
7+
8+
- Passing the undocumented ``xmin`` or ``xmax`` arguments to
9+
:meth:`~matplotlib.axes.Axes.set_xlim` would silently override the ``left``
10+
and ``right`` arguments. :meth:`~matplotlib.axes.Axes.set_ylim` and the
11+
3D equivalents (e.g. :meth:`~mpl_toolkits.axes.Axes3D.set_zlim3d`) had a
12+
corresponding problem.
13+
The ``_min`` and ``_max`` arguments are now deprecated, and a ``TypeError``
14+
will be raised if they would override the earlier limit arguments.

lib/matplotlib/axes/_base.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,8 +3041,11 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
30413041
Whether to turn on autoscaling of the x-axis. True turns on,
30423042
False turns off (default action), None leaves unchanged.
30433043
3044-
ymin, ymax : scalar, optional
3045-
If passed, these arguments override bottom and top respectively.
3044+
xmin, xmax : scalar, optional
3045+
These arguments are deprecated and will be removed in a future
3046+
version. They are equivalent to left and right respectively,
3047+
and it is an error to pass both `xmin` and `left` or
3048+
`xmax` and `right`.
30463049
30473050
Returns
30483051
-------
@@ -3076,12 +3079,16 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
30763079
if right is None and iterable(left):
30773080
left, right = left
30783081
if xmin is not None:
3082+
cbook.warn_deprecated('3.0', name='`xmin`',
3083+
alternative='`left`', obj_type='argument')
30793084
if left is not None:
3080-
warnings.warn('xmin=%r overrides left=%r' % (xmin, left))
3085+
raise TypeError('Cannot pass both `xmin` and `left`')
30813086
left = xmin
30823087
if xmax is not None:
3088+
cbook.warn_deprecated('3.0', name='`xmax`',
3089+
alternative='`right`', obj_type='argument')
30833090
if right is not None:
3084-
warnings.warn('xmax=%r overrides right=%r' % (xmax, right))
3091+
raise TypeError('Cannot pass both `xmax` and `right`')
30853092
right = xmax
30863093

30873094
self._process_unit_info(xdata=(left, right))
@@ -3375,7 +3382,10 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
33753382
False turns off (default action), None leaves unchanged.
33763383
33773384
ymin, ymax : scalar, optional
3378-
If passed, these arguments override bottom and top respectively.
3385+
These arguments are deprecated and will be removed in a future
3386+
version. They are equivalent to bottom and top respectively,
3387+
and it is an error to pass both `xmin` and `bottom` or
3388+
`xmax` and `top`.
33793389
33803390
Returns
33813391
-------
@@ -3408,12 +3418,16 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
34083418
if top is None and iterable(bottom):
34093419
bottom, top = bottom
34103420
if ymin is not None:
3421+
cbook.warn_deprecated('3.0', name='`ymin`',
3422+
alternative='`bottom`', obj_type='argument')
34113423
if bottom is not None:
3412-
warnings.warn('ymin=%r overrides bottom=%r' % (ymin, bottom))
3424+
raise TypeError('Cannot pass both `ymin` and `bottom`')
34133425
bottom = ymin
34143426
if ymax is not None:
3427+
cbook.warn_deprecated('3.0', name='`ymax`',
3428+
alternative='`top`', obj_type='argument')
34153429
if top is not None:
3416-
warnings.warn('ymax=%r overrides top=%r' % (ymax, top))
3430+
raise TypeError('Cannot pass both `ymax` and `top`')
34173431
top = ymax
34183432

34193433
bottom = self._validate_converted_limits(bottom, self.convert_yunits)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,16 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
612612
if right is None and cbook.iterable(left):
613613
left, right = left
614614
if xmin is not None:
615+
cbook.warn_deprecated('3.0', name='`xmin`',
616+
alternative='`left`', obj_type='argument')
615617
if left is not None:
616-
warnings.warn('xmin=%r overrides left=%r' % (xmin, left))
618+
raise TypeError('Cannot pass both `xmin` and `left`')
617619
left = xmin
618620
if xmax is not None:
621+
cbook.warn_deprecated('3.0', name='`xmax`',
622+
alternative='`right`', obj_type='argument')
619623
if right is not None:
620-
warnings.warn('xmax=%r overrides right=%r' % (xmax, right))
624+
raise TypeError('Cannot pass both `xmax` and `right`')
621625
right = xmax
622626

623627
self._process_unit_info(xdata=(left, right))
@@ -666,12 +670,16 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
666670
if top is None and cbook.iterable(bottom):
667671
bottom, top = bottom
668672
if ymin is not None:
673+
cbook.warn_deprecated('3.0', name='`ymin`',
674+
alternative='`bottom`', obj_type='argument')
669675
if bottom is not None:
670-
warnings.warn('ymin=%r overrides bottom=%r' % (ymin, bottom))
676+
raise TypeError('Cannot pass both `ymin` and `bottom`')
671677
bottom = ymin
672678
if ymax is not None:
679+
cbook.warn_deprecated('3.0', name='`ymax`',
680+
alternative='`top`', obj_type='argument')
673681
if top is not None:
674-
warnings.warn('ymax=%r overrides top=%r' % (ymax, top))
682+
raise TypeError('Cannot pass both `ymax` and `top`')
675683
top = ymax
676684

677685
self._process_unit_info(ydata=(bottom, top))
@@ -720,12 +728,16 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
720728
if top is None and cbook.iterable(bottom):
721729
bottom, top = bottom
722730
if zmin is not None:
731+
cbook.warn_deprecated('3.0', name='`zmin`',
732+
alternative='`bottom`', obj_type='argument')
723733
if bottom is not None:
724-
warnings.warn('zmin=%r overrides bottom=%r' % (zmin, bottom))
734+
raise TypeError('Cannot pass both `zmin` and `bottom`')
725735
bottom = zmin
726736
if zmax is not None:
737+
cbook.warn_deprecated('3.0', name='`zmax`',
738+
alternative='`top`', obj_type='argument')
727739
if top is not None:
728-
warnings.warn('zmax=%r overrides top=%r' % (zmax, top))
740+
raise TypeError('Cannot pass both `zmax` and `top`')
729741
top = zmax
730742

731743
self._process_unit_info(zdata=(bottom, top))

0 commit comments

Comments
 (0)