@@ -3011,46 +3011,42 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
30113011 if tight is not None :
30123012 self ._tight = bool (tight )
30133013
3014- x_shared = self ._shared_axes ["x" ].get_siblings (self )
3015- y_shared = self ._shared_axes ["y" ].get_siblings (self )
3014+ x_shared_axes = self ._shared_axes ["x" ].get_siblings (self )
3015+ y_shared_axes = self ._shared_axes ["y" ].get_siblings (self )
30163016
30173017 x_stickies = y_stickies = np .array ([])
30183018 if self .use_sticky_edges :
3019- # Use ._children and ._sticky_edges directly, because most extra
3020- # artists in .get_children() (spines, titles, etc.) never have
3021- # sticky edges. We also check axis objects since they can have
3022- # sticky edges (e.g. polar RadialAxis).
30233019 if self ._xmargin and scalex and self .get_autoscalex_on ():
3024- x_sticky_lists = []
3025- for ax in x_shared :
3026- for artist in ( * ax ._children , * ax . _axis_map . values () ):
3020+ x_sticky = []
3021+ for ax in x_shared_axes :
3022+ for artist in ax ._get_data_children ( ):
30273023 sticky_edges = artist ._sticky_edges
30283024 if sticky_edges is not None and sticky_edges .x :
3029- x_sticky_lists . append (sticky_edges .x )
3030- if x_sticky_lists :
3031- x_stickies = np .sort (np . concatenate ( x_sticky_lists ) )
3025+ x_sticky . extend (sticky_edges .x )
3026+ if x_sticky :
3027+ x_stickies = np .sort (x_sticky )
30323028 if self ._ymargin and scaley and self .get_autoscaley_on ():
3033- y_sticky_lists = []
3034- for ax in y_shared :
3035- for artist in ( * ax ._children , * ax . _axis_map . values () ):
3029+ y_sticky = []
3030+ for ax in y_shared_axes :
3031+ for artist in ax ._get_data_children ( ):
30363032 sticky_edges = artist ._sticky_edges
30373033 if sticky_edges is not None and sticky_edges .y :
3038- y_sticky_lists . append (sticky_edges .y )
3039- if y_sticky_lists :
3040- y_stickies = np .sort (np . concatenate ( y_sticky_lists ) )
3034+ y_sticky . extend (sticky_edges .y )
3035+ if y_sticky :
3036+ y_stickies = np .sort (y_sticky )
30413037 if self .get_xscale () == 'log' :
30423038 x_stickies = x_stickies [x_stickies > 0 ]
30433039 if self .get_yscale () == 'log' :
30443040 y_stickies = y_stickies [y_stickies > 0 ]
30453041
30463042 def handle_single_axis (
3047- scale , shared , name , axis , margin , stickies , set_bound ):
3043+ scale , shared_axes , name , axis , margin , stickies , set_bound ):
30483044
30493045 if not (scale and axis ._get_autoscale_on ()):
30503046 return # nothing to do...
30513047 # Base autoscaling on finite data limits when there is at least one
30523048 # finite data limit among all the shared_axes and intervals.
3053- values = [val for ax in shared
3049+ values = [val for ax in shared_axes
30543050 for val in getattr (ax .dataLim , f"interval{ name } " )
30553051 if np .isfinite (val )]
30563052 if values :
@@ -3066,13 +3062,14 @@ def handle_single_axis(
30663062 x0 , x1 = locator .nonsingular (x0 , x1 )
30673063 # Find the minimum minpos for use in the margin calculation.
30683064 minimum_minpos = min (
3069- getattr (ax .dataLim , f"minpos{ name } " ) for ax in shared )
3065+ getattr (ax .dataLim , f"minpos{ name } " ) for ax in shared_axes )
30703066
30713067 # Prevent margin addition from crossing a sticky value. A small
30723068 # tolerance must be added due to floating point issues with
30733069 # streamplot; it is defined relative to x1-x0 but has
30743070 # no absolute term (e.g. "+1e-8") to avoid issues when working with
30753071 # datasets where all values are tiny (less than 1e-8).
3072+ x0bound = x1bound = None
30763073 if len (stickies ):
30773074 tol = 1e-5 * abs (x1 - x0 )
30783075 # Index of largest element < x0 + tol, if any.
@@ -3081,8 +3078,6 @@ def handle_single_axis(
30813078 # Index of smallest element > x1 - tol, if any.
30823079 i1 = stickies .searchsorted (x1 - tol )
30833080 x1bound = stickies [i1 ] if i1 != len (stickies ) else None
3084- else :
3085- x0bound = x1bound = None
30863081
30873082 # Add the margin in figure space and then transform back, to handle
30883083 # non-linear scales.
@@ -3107,10 +3102,10 @@ def handle_single_axis(
31073102 # End of definition of internal function 'handle_single_axis'.
31083103
31093104 handle_single_axis (
3110- scalex , x_shared , 'x' , self .xaxis , self ._xmargin ,
3105+ scalex , x_shared_axes , 'x' , self .xaxis , self ._xmargin ,
31113106 x_stickies , self .set_xbound )
31123107 handle_single_axis (
3113- scaley , y_shared , 'y' , self .yaxis , self ._ymargin ,
3108+ scaley , y_shared_axes , 'y' , self .yaxis , self ._ymargin ,
31143109 y_stickies , self .set_ybound )
31153110
31163111 def _update_title_position (self , renderer ):
@@ -4513,6 +4508,17 @@ def drag_pan(self, button, key, x, y):
45134508 self .set_xlim (points [:, 0 ])
45144509 self .set_ylim (points [:, 1 ])
45154510
4511+ def _get_data_children (self ):
4512+ """
4513+ Return artists that represent data (plot lines, collections, images,
4514+ patches, etc.) as opposed to auxiliary artists needed to draw the
4515+ Axes itself (spines, titles, axis objects, etc.).
4516+
4517+ Data children are the artists that can contribute to autoscaling
4518+ and sticky edges.
4519+ """
4520+ return [* self ._children , * self ._axis_map .values ()]
4521+
45164522 def get_children (self ):
45174523 # docstring inherited.
45184524 return [
0 commit comments