@@ -665,6 +665,8 @@ def __init__(self, fig,
665
665
self .set_box_aspect (box_aspect )
666
666
self ._axes_locator = None # Optionally set via update(kwargs).
667
667
668
+ self ._children = []
669
+
668
670
# placeholder for any colorbars added that use this Axes.
669
671
# (see colorbar.py):
670
672
self ._colorbars = []
@@ -1078,7 +1080,7 @@ def _update_transScale(self):
1078
1080
self .transScale .set (
1079
1081
mtransforms .blended_transform_factory (
1080
1082
self .xaxis .get_transform (), self .yaxis .get_transform ()))
1081
- for line in getattr ( self , " _children" , []): # Not set during init.
1083
+ for line in self . _children :
1082
1084
if not isinstance (line , mlines .Line2D ):
1083
1085
continue
1084
1086
try :
@@ -1291,14 +1293,6 @@ def __clear(self):
1291
1293
self .callbacks = cbook .CallbackRegistry (
1292
1294
signals = ["xlim_changed" , "ylim_changed" , "zlim_changed" ])
1293
1295
1294
- for name , axis in self ._axis_map .items ():
1295
- share = getattr (self , f"_share{ name } " )
1296
- if share is not None :
1297
- getattr (self , f"share{ name } " )(share )
1298
- else :
1299
- axis ._set_scale ("linear" )
1300
- axis ._set_lim (0 , 1 , auto = True )
1301
-
1302
1296
# update the minor locator for x and y axis based on rcParams
1303
1297
if mpl .rcParams ['xtick.minor.visible' ]:
1304
1298
self .xaxis .set_minor_locator (mticker .AutoMinorLocator ())
@@ -1309,7 +1303,6 @@ def __clear(self):
1309
1303
self ._ymargin = mpl .rcParams ['axes.ymargin' ]
1310
1304
self ._tight = None
1311
1305
self ._use_sticky_edges = True
1312
- self ._update_transScale () # needed?
1313
1306
1314
1307
self ._get_lines = _process_plot_var_args (self )
1315
1308
self ._get_patches_for_fill = _process_plot_var_args (self , 'fill' )
@@ -1386,6 +1379,17 @@ def __clear(self):
1386
1379
self .yaxis .set_visible (yaxis_visible )
1387
1380
self .patch .set_visible (patch_visible )
1388
1381
1382
+ # This comes last, as the call to _set_lim may trigger an autoscale (in
1383
+ # case of shared axes), requiring children to be already set up.
1384
+ for name , axis in self ._axis_map .items ():
1385
+ share = getattr (self , f"_share{ name } " )
1386
+ if share is not None :
1387
+ getattr (self , f"share{ name } " )(share )
1388
+ else :
1389
+ axis ._set_scale ("linear" )
1390
+ axis ._set_lim (0 , 1 , auto = True )
1391
+ self ._update_transScale ()
1392
+
1389
1393
self .stale = True
1390
1394
1391
1395
def clear (self ):
@@ -2936,22 +2940,15 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
2936
2940
2937
2941
x_stickies = y_stickies = np .array ([])
2938
2942
if self .use_sticky_edges :
2939
- # Only iterate over Axes and artists if needed. The check for
2940
- # ``hasattr(ax, "_children")`` is necessary because this can be
2941
- # called very early in the Axes init process (e.g., for twin Axes)
2942
- # when these attributes don't even exist yet, in which case
2943
- # `get_children` would raise an AttributeError.
2944
2943
if self ._xmargin and scalex and self .get_autoscalex_on ():
2945
2944
x_stickies = np .sort (np .concatenate ([
2946
2945
artist .sticky_edges .x
2947
2946
for ax in self ._shared_axes ["x" ].get_siblings (self )
2948
- if hasattr (ax , "_children" )
2949
2947
for artist in ax .get_children ()]))
2950
2948
if self ._ymargin and scaley and self .get_autoscaley_on ():
2951
2949
y_stickies = np .sort (np .concatenate ([
2952
2950
artist .sticky_edges .y
2953
2951
for ax in self ._shared_axes ["y" ].get_siblings (self )
2954
- if hasattr (ax , "_children" )
2955
2952
for artist in ax .get_children ()]))
2956
2953
if self .get_xscale () == 'log' :
2957
2954
x_stickies = x_stickies [x_stickies > 0 ]
0 commit comments