@@ -3630,9 +3630,8 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
3630
3630
False turns off, None leaves unchanged.
3631
3631
3632
3632
xmin, xmax : float, optional
3633
- They are equivalent to left and right respectively,
3634
- and it is an error to pass both *xmin* and *left* or
3635
- *xmax* and *right*.
3633
+ They are equivalent to left and right respectively, and it is an
3634
+ error to pass both *xmin* and *left* or *xmax* and *right*.
3636
3635
3637
3636
Returns
3638
3637
-------
@@ -3667,76 +3666,9 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
3667
3666
present is on the right.
3668
3667
3669
3668
>>> set_xlim(5000, 0)
3670
-
3671
3669
"""
3672
- if right is None and np .iterable (left ):
3673
- left , right = left
3674
- if xmin is not None :
3675
- if left is not None :
3676
- raise TypeError ('Cannot pass both `xmin` and `left`' )
3677
- left = xmin
3678
- if xmax is not None :
3679
- if right is not None :
3680
- raise TypeError ('Cannot pass both `xmax` and `right`' )
3681
- right = xmax
3682
-
3683
- self ._process_unit_info ([("x" , (left , right ))], convert = False )
3684
- left = self ._validate_converted_limits (left , self .convert_xunits )
3685
- right = self ._validate_converted_limits (right , self .convert_xunits )
3686
-
3687
- if left is None or right is None :
3688
- # Axes init calls set_xlim(0, 1) before get_xlim() can be called,
3689
- # so only grab the limits if we really need them.
3690
- old_left , old_right = self .get_xlim ()
3691
- if left is None :
3692
- left = old_left
3693
- if right is None :
3694
- right = old_right
3695
-
3696
- if self .get_xscale () == 'log' and (left <= 0 or right <= 0 ):
3697
- # Axes init calls set_xlim(0, 1) before get_xlim() can be called,
3698
- # so only grab the limits if we really need them.
3699
- old_left , old_right = self .get_xlim ()
3700
- if left <= 0 :
3701
- _api .warn_external (
3702
- 'Attempted to set non-positive left xlim on a '
3703
- 'log-scaled axis.\n '
3704
- 'Invalid limit will be ignored.' )
3705
- left = old_left
3706
- if right <= 0 :
3707
- _api .warn_external (
3708
- 'Attempted to set non-positive right xlim on a '
3709
- 'log-scaled axis.\n '
3710
- 'Invalid limit will be ignored.' )
3711
- right = old_right
3712
- if left == right :
3713
- _api .warn_external (
3714
- f"Attempting to set identical left == right == { left } results "
3715
- f"in singular transformations; automatically expanding." )
3716
- reverse = left > right
3717
- left , right = self .xaxis .get_major_locator ().nonsingular (left , right )
3718
- left , right = self .xaxis .limit_range_for_scale (left , right )
3719
- # cast to bool to avoid bad interaction between python 3.8 and np.bool_
3720
- left , right = sorted ([left , right ], reverse = bool (reverse ))
3721
-
3722
- self ._viewLim .intervalx = (left , right )
3723
- # Mark viewlims as no longer stale without triggering an autoscale.
3724
- for ax in self ._shared_axes ["x" ].get_siblings (self ):
3725
- ax ._stale_viewlims ["x" ] = False
3726
- if auto is not None :
3727
- self ._autoscaleXon = bool (auto )
3728
-
3729
- if emit :
3730
- self .callbacks .process ('xlim_changed' , self )
3731
- # Call all of the other x-axes that are shared with this one
3732
- for other in self ._shared_axes ["x" ].get_siblings (self ):
3733
- if other is not self :
3734
- other .set_xlim (self .viewLim .intervalx ,
3735
- emit = False , auto = auto )
3736
- if other .figure != self .figure :
3737
- other .figure .canvas .draw_idle ()
3738
- self .stale = True
3739
- return left , right
3670
+ return self .xaxis ._set_lim (
3671
+ "left" , "right" , left , right , xmin , xmax , emit = emit , auto = auto )
3740
3672
3741
3673
get_xscale = _axis_method_wrapper ("xaxis" , "get_scale" )
3742
3674
@@ -3957,9 +3889,8 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
3957
3889
*False* turns off, *None* leaves unchanged.
3958
3890
3959
3891
ymin, ymax : float, optional
3960
- They are equivalent to bottom and top respectively,
3961
- and it is an error to pass both *ymin* and *bottom* or
3962
- *ymax* and *top*.
3892
+ They are equivalent to bottom and top respectively, and it is an
3893
+ error to pass both *ymin* and *bottom* or *ymax* and *top*.
3963
3894
3964
3895
Returns
3965
3896
-------
@@ -3995,75 +3926,8 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
3995
3926
3996
3927
>>> set_ylim(5000, 0)
3997
3928
"""
3998
- if top is None and np .iterable (bottom ):
3999
- bottom , top = bottom
4000
- if ymin is not None :
4001
- if bottom is not None :
4002
- raise TypeError ('Cannot pass both `ymin` and `bottom`' )
4003
- bottom = ymin
4004
- if ymax is not None :
4005
- if top is not None :
4006
- raise TypeError ('Cannot pass both `ymax` and `top`' )
4007
- top = ymax
4008
-
4009
- self ._process_unit_info ([("y" , (bottom , top ))], convert = False )
4010
- bottom = self ._validate_converted_limits (bottom , self .convert_yunits )
4011
- top = self ._validate_converted_limits (top , self .convert_yunits )
4012
-
4013
- if bottom is None or top is None :
4014
- # Axes init calls set_ylim(0, 1) before get_ylim() can be called,
4015
- # so only grab the limits if we really need them.
4016
- old_bottom , old_top = self .get_ylim ()
4017
- if bottom is None :
4018
- bottom = old_bottom
4019
- if top is None :
4020
- top = old_top
4021
-
4022
- if self .get_yscale () == 'log' and (bottom <= 0 or top <= 0 ):
4023
- # Axes init calls set_xlim(0, 1) before get_xlim() can be called,
4024
- # so only grab the limits if we really need them.
4025
- old_bottom , old_top = self .get_ylim ()
4026
- if bottom <= 0 :
4027
- _api .warn_external (
4028
- 'Attempted to set non-positive bottom ylim on a '
4029
- 'log-scaled axis.\n '
4030
- 'Invalid limit will be ignored.' )
4031
- bottom = old_bottom
4032
- if top <= 0 :
4033
- _api .warn_external (
4034
- 'Attempted to set non-positive top ylim on a '
4035
- 'log-scaled axis.\n '
4036
- 'Invalid limit will be ignored.' )
4037
- top = old_top
4038
- if bottom == top :
4039
- _api .warn_external (
4040
- f"Attempting to set identical bottom == top == { bottom } "
4041
- f"results in singular transformations; automatically "
4042
- f"expanding." )
4043
- reverse = bottom > top
4044
- bottom , top = self .yaxis .get_major_locator ().nonsingular (bottom , top )
4045
- bottom , top = self .yaxis .limit_range_for_scale (bottom , top )
4046
- # cast to bool to avoid bad interaction between python 3.8 and np.bool_
4047
- bottom , top = sorted ([bottom , top ], reverse = bool (reverse ))
4048
-
4049
- self ._viewLim .intervaly = (bottom , top )
4050
- # Mark viewlims as no longer stale without triggering an autoscale.
4051
- for ax in self ._shared_axes ["y" ].get_siblings (self ):
4052
- ax ._stale_viewlims ["y" ] = False
4053
- if auto is not None :
4054
- self ._autoscaleYon = bool (auto )
4055
-
4056
- if emit :
4057
- self .callbacks .process ('ylim_changed' , self )
4058
- # Call all of the other y-axes that are shared with this one
4059
- for other in self ._shared_axes ["y" ].get_siblings (self ):
4060
- if other is not self :
4061
- other .set_ylim (self .viewLim .intervaly ,
4062
- emit = False , auto = auto )
4063
- if other .figure != self .figure :
4064
- other .figure .canvas .draw_idle ()
4065
- self .stale = True
4066
- return bottom , top
3929
+ return self .yaxis ._set_lim (
3930
+ "bottom" , "top" , bottom , top , ymin , ymax , emit = emit , auto = auto )
4067
3931
4068
3932
get_yscale = _axis_method_wrapper ("yaxis" , "get_scale" )
4069
3933
0 commit comments