@@ -3011,30 +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 )
3016+
30143017 x_stickies = y_stickies = np .array ([])
30153018 if self .use_sticky_edges :
30163019 if self ._xmargin and scalex and self .get_autoscalex_on ():
3017- x_stickies = np .sort (np .concatenate ([
3018- artist .sticky_edges .x
3019- for ax in self ._shared_axes ["x" ].get_siblings (self )
3020- for artist in ax .get_children ()]))
3020+ # Use ._children and ._sticky_edges directly, because the extra
3021+ # artists in .get_children() (spines, axes, titles, etc.) never
3022+ # have sticky edges, so we can skip them for performance.
3023+ x_sticky_lists = [
3024+ sticky_edges_x
3025+ for ax in x_shared
3026+ for artist in ax ._children
3027+ if (sticky_edges_x := artist ._sticky_edges .x ) # skip empty lists
3028+ ]
3029+ if x_sticky_lists :
3030+ x_stickies = np .sort (np .concatenate (x_sticky_lists ))
30213031 if self ._ymargin and scaley and self .get_autoscaley_on ():
3022- y_stickies = np .sort (np .concatenate ([
3023- artist .sticky_edges .y
3024- for ax in self ._shared_axes ["y" ].get_siblings (self )
3025- for artist in ax .get_children ()]))
3032+ y_sticky_lists = [
3033+ sticky_edges_y
3034+ for ax in y_shared
3035+ for artist in ax ._children
3036+ if (sticky_edges_y := artist ._sticky_edges .y ) # skip empty lists
3037+ ]
3038+ if y_sticky_lists :
3039+ y_stickies = np .sort (np .concatenate (y_sticky_lists ))
30263040 if self .get_xscale () == 'log' :
30273041 x_stickies = x_stickies [x_stickies > 0 ]
30283042 if self .get_yscale () == 'log' :
30293043 y_stickies = y_stickies [y_stickies > 0 ]
30303044
30313045 def handle_single_axis (
3032- scale , shared_axes , name , axis , margin , stickies , set_bound ):
3046+ scale , shared , name , axis , margin , stickies , set_bound ):
30333047
30343048 if not (scale and axis ._get_autoscale_on ()):
30353049 return # nothing to do...
3036-
3037- shared = shared_axes .get_siblings (self )
30383050 # Base autoscaling on finite data limits when there is at least one
30393051 # finite data limit among all the shared_axes and intervals.
30403052 values = [val for ax in shared
@@ -3091,10 +3103,10 @@ def handle_single_axis(
30913103 # End of definition of internal function 'handle_single_axis'.
30923104
30933105 handle_single_axis (
3094- scalex , self . _shared_axes [ "x" ] , 'x' , self .xaxis , self ._xmargin ,
3106+ scalex , x_shared , 'x' , self .xaxis , self ._xmargin ,
30953107 x_stickies , self .set_xbound )
30963108 handle_single_axis (
3097- scaley , self . _shared_axes [ "y" ] , 'y' , self .yaxis , self ._ymargin ,
3109+ scaley , y_shared , 'y' , self .yaxis , self ._ymargin ,
30983110 y_stickies , self .set_ybound )
30993111
31003112 def _update_title_position (self , renderer ):
0 commit comments