@@ -1212,6 +1212,7 @@ def cla(self):
12121212 self .set_xlim (0 , 1 )
12131213 except TypeError :
12141214 pass
1215+ self .set_autoscalex_on (True )
12151216 if self ._sharey is not None :
12161217 self .sharey (self ._sharey )
12171218 else :
@@ -1220,17 +1221,14 @@ def cla(self):
12201221 self .set_ylim (0 , 1 )
12211222 except TypeError :
12221223 pass
1224+ self .set_autoscaley_on (True )
12231225
12241226 # update the minor locator for x and y axis based on rcParams
12251227 if mpl .rcParams ['xtick.minor.visible' ]:
12261228 self .xaxis .set_minor_locator (mticker .AutoMinorLocator ())
12271229 if mpl .rcParams ['ytick.minor.visible' ]:
12281230 self .yaxis .set_minor_locator (mticker .AutoMinorLocator ())
12291231
1230- if self ._sharex is None :
1231- self ._autoscaleXon = True
1232- if self ._sharey is None :
1233- self ._autoscaleYon = True
12341232 self ._xmargin = mpl .rcParams ['axes.xmargin' ]
12351233 self ._ymargin = mpl .rcParams ['axes.ymargin' ]
12361234 self ._tight = None
@@ -2561,17 +2559,15 @@ def in_axes(self, mouseevent):
25612559 """
25622560 return self .patch .contains (mouseevent )[0 ]
25632561
2562+ get_autoscalex_on = _axis_method_wrapper ("xaxis" , "_get_autoscale_on" )
2563+ get_autoscaley_on = _axis_method_wrapper ("yaxis" , "_get_autoscale_on" )
2564+ set_autoscalex_on = _axis_method_wrapper ("xaxis" , "_set_autoscale_on" )
2565+ set_autoscaley_on = _axis_method_wrapper ("yaxis" , "_set_autoscale_on" )
2566+
25642567 def get_autoscale_on (self ):
25652568 """Return True if each axis is autoscaled, False otherwise."""
2566- return self ._autoscaleXon and self ._autoscaleYon
2567-
2568- def get_autoscalex_on (self ):
2569- """Return whether the x-axis is autoscaled."""
2570- return self ._autoscaleXon
2571-
2572- def get_autoscaley_on (self ):
2573- """Return whether the y-axis is autoscaled."""
2574- return self ._autoscaleYon
2569+ return all (axis ._get_autoscale_on ()
2570+ for axis in self ._get_axis_map ().values ())
25752571
25762572 def set_autoscale_on (self , b ):
25772573 """
@@ -2582,30 +2578,8 @@ def set_autoscale_on(self, b):
25822578 ----------
25832579 b : bool
25842580 """
2585- self ._autoscaleXon = b
2586- self ._autoscaleYon = b
2587-
2588- def set_autoscalex_on (self , b ):
2589- """
2590- Set whether the x-axis is autoscaled on the next draw or call to
2591- `.Axes.autoscale_view`.
2592-
2593- Parameters
2594- ----------
2595- b : bool
2596- """
2597- self ._autoscaleXon = b
2598-
2599- def set_autoscaley_on (self , b ):
2600- """
2601- Set whether the y-axis is autoscaled on the next draw or call to
2602- `.Axes.autoscale_view`.
2603-
2604- Parameters
2605- ----------
2606- b : bool
2607- """
2608- self ._autoscaleYon = b
2581+ for axis in self ._get_axis_map ().values ():
2582+ axis ._set_autoscale_on (b )
26092583
26102584 @property
26112585 def use_sticky_edges (self ):
@@ -2798,14 +2772,16 @@ def autoscale(self, enable=True, axis='both', tight=None):
27982772 scalex = True
27992773 scaley = True
28002774 else :
2801- scalex = False
2802- scaley = False
28032775 if axis in ['x' , 'both' ]:
2804- self ._autoscaleXon = bool (enable )
2805- scalex = self ._autoscaleXon
2776+ self .set_autoscalex_on (bool (enable ))
2777+ scalex = self .get_autoscalex_on ()
2778+ else :
2779+ scalex = False
28062780 if axis in ['y' , 'both' ]:
2807- self ._autoscaleYon = bool (enable )
2808- scaley = self ._autoscaleYon
2781+ self .set_autoscaley_on (bool (enable ))
2782+ scaley = self .get_autoscaley_on ()
2783+ else :
2784+ scaley = False
28092785 if tight and scalex :
28102786 self ._xmargin = 0
28112787 if tight and scaley :
@@ -2864,13 +2840,13 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
28642840 # called very early in the Axes init process (e.g., for twin Axes)
28652841 # when these attributes don't even exist yet, in which case
28662842 # `get_children` would raise an AttributeError.
2867- if self ._xmargin and scalex and self ._autoscaleXon :
2843+ if self ._xmargin and scalex and self .get_autoscalex_on () :
28682844 x_stickies = np .sort (np .concatenate ([
28692845 artist .sticky_edges .x
28702846 for ax in self ._shared_axes ["x" ].get_siblings (self )
28712847 if hasattr (ax , "_children" )
28722848 for artist in ax .get_children ()]))
2873- if self ._ymargin and scaley and self ._autoscaleYon :
2849+ if self ._ymargin and scaley and self .get_autoscaley_on () :
28742850 y_stickies = np .sort (np .concatenate ([
28752851 artist .sticky_edges .y
28762852 for ax in self ._shared_axes ["y" ].get_siblings (self )
@@ -2881,10 +2857,10 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
28812857 if self .get_yscale () == 'log' :
28822858 y_stickies = y_stickies [y_stickies > 0 ]
28832859
2884- def handle_single_axis (scale , autoscaleon , shared_axes , name ,
2885- axis , margin , stickies , set_bound ):
2860+ def handle_single_axis (
2861+ scale , shared_axes , name , axis , margin , stickies , set_bound ):
28862862
2887- if not (scale and autoscaleon ):
2863+ if not (scale and axis . _get_autoscale_on () ):
28882864 return # nothing to do...
28892865
28902866 shared = shared_axes .get_siblings (self )
@@ -2947,11 +2923,11 @@ def handle_single_axis(scale, autoscaleon, shared_axes, name,
29472923 # End of definition of internal function 'handle_single_axis'.
29482924
29492925 handle_single_axis (
2950- scalex , self ._autoscaleXon , self . _shared_axes ["x" ], 'x' ,
2951- self . xaxis , self . _xmargin , x_stickies , self .set_xbound )
2926+ scalex , self ._shared_axes ["x" ], 'x' , self . xaxis , self . _xmargin ,
2927+ x_stickies , self .set_xbound )
29522928 handle_single_axis (
2953- scaley , self ._autoscaleYon , self . _shared_axes ["y" ], 'y' ,
2954- self . yaxis , self . _ymargin , y_stickies , self .set_ybound )
2929+ scaley , self ._shared_axes ["y" ], 'y' , self . yaxis , self . _ymargin ,
2930+ y_stickies , self .set_ybound )
29552931
29562932 def _get_axis_list (self ):
29572933 return tuple (getattr (self , f"{ name } axis" ) for name in self ._axis_names )
0 commit comments