@@ -1212,6 +1212,7 @@ def cla(self):
1212
1212
self .set_xlim (0 , 1 )
1213
1213
except TypeError :
1214
1214
pass
1215
+ self .set_autoscalex_on (True )
1215
1216
if self ._sharey is not None :
1216
1217
self .sharey (self ._sharey )
1217
1218
else :
@@ -1220,17 +1221,14 @@ def cla(self):
1220
1221
self .set_ylim (0 , 1 )
1221
1222
except TypeError :
1222
1223
pass
1224
+ self .set_autoscaley_on (True )
1223
1225
1224
1226
# update the minor locator for x and y axis based on rcParams
1225
1227
if mpl .rcParams ['xtick.minor.visible' ]:
1226
1228
self .xaxis .set_minor_locator (mticker .AutoMinorLocator ())
1227
1229
if mpl .rcParams ['ytick.minor.visible' ]:
1228
1230
self .yaxis .set_minor_locator (mticker .AutoMinorLocator ())
1229
1231
1230
- if self ._sharex is None :
1231
- self ._autoscaleXon = True
1232
- if self ._sharey is None :
1233
- self ._autoscaleYon = True
1234
1232
self ._xmargin = mpl .rcParams ['axes.xmargin' ]
1235
1233
self ._ymargin = mpl .rcParams ['axes.ymargin' ]
1236
1234
self ._tight = None
@@ -2561,17 +2559,15 @@ def in_axes(self, mouseevent):
2561
2559
"""
2562
2560
return self .patch .contains (mouseevent )[0 ]
2563
2561
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
+
2564
2567
def get_autoscale_on (self ):
2565
2568
"""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 ())
2575
2571
2576
2572
def set_autoscale_on (self , b ):
2577
2573
"""
@@ -2582,30 +2578,8 @@ def set_autoscale_on(self, b):
2582
2578
----------
2583
2579
b : bool
2584
2580
"""
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 )
2609
2583
2610
2584
@property
2611
2585
def use_sticky_edges (self ):
@@ -2798,14 +2772,16 @@ def autoscale(self, enable=True, axis='both', tight=None):
2798
2772
scalex = True
2799
2773
scaley = True
2800
2774
else :
2801
- scalex = False
2802
- scaley = False
2803
2775
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
2806
2780
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
2809
2785
if tight and scalex :
2810
2786
self ._xmargin = 0
2811
2787
if tight and scaley :
@@ -2864,13 +2840,13 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
2864
2840
# called very early in the Axes init process (e.g., for twin Axes)
2865
2841
# when these attributes don't even exist yet, in which case
2866
2842
# `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 () :
2868
2844
x_stickies = np .sort (np .concatenate ([
2869
2845
artist .sticky_edges .x
2870
2846
for ax in self ._shared_axes ["x" ].get_siblings (self )
2871
2847
if hasattr (ax , "_children" )
2872
2848
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 () :
2874
2850
y_stickies = np .sort (np .concatenate ([
2875
2851
artist .sticky_edges .y
2876
2852
for ax in self ._shared_axes ["y" ].get_siblings (self )
@@ -2881,10 +2857,10 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
2881
2857
if self .get_yscale () == 'log' :
2882
2858
y_stickies = y_stickies [y_stickies > 0 ]
2883
2859
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 ):
2886
2862
2887
- if not (scale and autoscaleon ):
2863
+ if not (scale and axis . _get_autoscale_on () ):
2888
2864
return # nothing to do...
2889
2865
2890
2866
shared = shared_axes .get_siblings (self )
@@ -2947,11 +2923,11 @@ def handle_single_axis(scale, autoscaleon, shared_axes, name,
2947
2923
# End of definition of internal function 'handle_single_axis'.
2948
2924
2949
2925
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 )
2952
2928
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 )
2955
2931
2956
2932
def _get_axis_list (self ):
2957
2933
return tuple (getattr (self , f"{ name } axis" ) for name in self ._axis_names )
0 commit comments