@@ -2817,15 +2817,33 @@ def get_xlim(self):
2817
2817
"""
2818
2818
return tuple (self .viewLim .intervalx )
2819
2819
2820
- def _set_lim (self , axis , low , high , low_name , high_name ,
2821
- target_obj , target_attr , emit , auto , kw ):
2822
- """Helper factoring the functionality of `get_{x,y,z}lim`."""
2823
- # Perhaps we can use axis.{get,set}_view_interval()... but zaxis seems
2824
- # to behave differently.
2825
- _called_from_pan = kw .pop ("_called_from_pan" , False )
2826
- if kw :
2827
- raise ValueError ("Unrecognized kwargs: {}" .format (kw ))
2828
- axis_name = axis .axis_name
2820
+ def _set_lim (self , axis , axis_name , low , high , low_name , high_name ,
2821
+ target_obj , target_attr , emit , auto ):
2822
+ """Helper factoring the functionality of ``set_{x,y,z}lim``.
2823
+
2824
+ Parameters
2825
+ ----------
2826
+ axis : Axis
2827
+ The target axis.
2828
+ axis_name : str
2829
+ The axis name to use in ``get_?lim`` and ``_autoscale?on``. (Not
2830
+ ``axis.axis_name`` because the name of `.RadianAxes` is "radius",
2831
+ not "r". Not using ``axis.{get,set}_view_interval`` because 3D
2832
+ axes behave differently.)
2833
+ low, high :
2834
+ The first two arguments passed to `set_xlim` (and other
2835
+ axes). Either both ``Optional[float]``, or a pair of two
2836
+ ``Optional[float]`` and ``None``.
2837
+ low_name, high_name : str
2838
+ Names of the "low" and "high" arguments, for generating error
2839
+ messages.
2840
+ target_obj, target_attr :
2841
+ Target object holding the limits. The limits are applied as
2842
+ ``target_obj.target_attr = low, high`` (after default handling,
2843
+ unit conversion, and validation).
2844
+ emit, auto :
2845
+ See docstring of `set_xlim` (etc.).
2846
+ """
2829
2847
if high is None and iterable (low ):
2830
2848
low , high = low
2831
2849
old_low , old_high = getattr (self , "get_{}lim" .format (axis_name ))()
@@ -2836,8 +2854,7 @@ def _set_lim(self, axis, low, high, low_name, high_name,
2836
2854
self ._process_unit_info (** {"{}data" .format (axis_name ): [low , high ]})
2837
2855
low , high = map (axis .convert_units , [low , high ])
2838
2856
for limit in [low , high ]:
2839
- if not (_called_from_pan or
2840
- np .isreal (limit ) and np .isfinite (limit )):
2857
+ if not (np .isreal (limit ) and np .isfinite (limit )):
2841
2858
raise ValueError (
2842
2859
"Axis limits must be (or convert to) finite reals" )
2843
2860
if low == high :
@@ -2928,8 +2945,8 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
2928
2945
left = kw .pop ('xmin' )
2929
2946
if 'xmax' in kw :
2930
2947
right = kw .pop ('xmax' )
2931
- return self ._set_lim (self .xaxis , left , right , "left" , "right" ,
2932
- self .viewLim , "intervalx" , emit , auto , kw )
2948
+ return self ._set_lim (self .xaxis , "x" , left , right , "left" , "right" ,
2949
+ self .viewLim , "intervalx" , emit , auto , ** kw )
2933
2950
2934
2951
def get_xscale (self ):
2935
2952
return self .xaxis .get_scale ()
@@ -3206,8 +3223,8 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
3206
3223
bottom = kw .pop ('ymin' )
3207
3224
if 'ymax' in kw :
3208
3225
top = kw .pop ('ymax' )
3209
- return self ._set_lim (self .yaxis , bottom , top , "bottom" , "top" ,
3210
- self .viewLim , "intervaly" , emit , auto , kw )
3226
+ return self ._set_lim (self .yaxis , "y" , bottom , top , "bottom" , "top" ,
3227
+ self .viewLim , "intervaly" , emit , auto , ** kw )
3211
3228
3212
3229
def get_yscale (self ):
3213
3230
return self .yaxis .get_scale ()
@@ -3776,8 +3793,12 @@ def format_deltas(key, dx, dy):
3776
3793
warnings .warn ('Overflow while panning' )
3777
3794
return
3778
3795
3779
- self .set_xlim (* result .intervalx , _called_from_pan = True )
3780
- self .set_ylim (* result .intervaly , _called_from_pan = True )
3796
+ valid = np .isfinite (result .transformed (p .trans ))
3797
+ points = result .get_points ().astype (object )
3798
+ # Just ignore invalid limits (typically, underflow in log-scale).
3799
+ points [~ valid ] = None
3800
+ self .set_xlim (points [:, 0 ])
3801
+ self .set_ylim (points [:, 1 ])
3781
3802
3782
3803
@cbook .deprecated ("2.1" )
3783
3804
def get_cursor_props (self ):
0 commit comments