@@ -779,24 +779,26 @@ def viewLim(self):
779
779
self ._unstale_viewLim ()
780
780
return self ._viewLim
781
781
782
- # API could be better, right now this is just to match the old calls to
783
- # autoscale_view() after each plotting method.
784
- def _request_autoscale_view (self , tight = None , ** kwargs ):
785
- # kwargs are "scalex", "scaley" (& "scalez" for 3D) and default to True
786
- want_scale = {name : True for name in self ._axis_names }
787
- for k , v in kwargs .items (): # Validate args before changing anything.
788
- if k .startswith ("scale" ):
789
- name = k [5 :]
790
- if name in want_scale :
791
- want_scale [name ] = v
792
- continue
793
- raise TypeError (
794
- f"_request_autoscale_view() got an unexpected argument { k !r} " )
782
+ def _request_autoscale_view (self , axis = "all" , tight = None ):
783
+ """
784
+ Mark a single axis, or all of them, as stale wrt. autoscaling.
785
+
786
+ No computation is performed until the next autoscaling; thus, separate
787
+ calls to control individual axises incur negligible performance cost.
788
+
789
+ Parameters
790
+ ----------
791
+ axis : str, default: "all"
792
+ Either an element of ``self._axis_names``, or "all".
793
+ tight : bool or None, default: None
794
+ """
795
+ axis_names = _api .check_getitem (
796
+ {** {k : [k ] for k in self ._axis_names }, "all" : self ._axis_names },
797
+ axis = axis )
798
+ for name in axis_names :
799
+ self ._stale_viewlims [name ] = True
795
800
if tight is not None :
796
801
self ._tight = tight
797
- for k , v in want_scale .items ():
798
- if v :
799
- self ._stale_viewlims [k ] = True # Else keep old state.
800
802
801
803
def _set_lim_and_transforms (self ):
802
804
"""
@@ -2424,8 +2426,7 @@ def _unit_change_handler(self, axis_name, event=None):
2424
2426
for line in self .lines :
2425
2427
line .recache_always ()
2426
2428
self .relim ()
2427
- self ._request_autoscale_view (scalex = (axis_name == "x" ),
2428
- scaley = (axis_name == "y" ))
2429
+ self ._request_autoscale_view (axis_name )
2429
2430
2430
2431
def relim (self , visible_only = False ):
2431
2432
"""
@@ -2632,7 +2633,7 @@ def set_xmargin(self, m):
2632
2633
if m <= - 0.5 :
2633
2634
raise ValueError ("margin must be greater than -0.5" )
2634
2635
self ._xmargin = m
2635
- self ._request_autoscale_view (scalex = True , scaley = False )
2636
+ self ._request_autoscale_view ("x" )
2636
2637
self .stale = True
2637
2638
2638
2639
def set_ymargin (self , m ):
@@ -2654,7 +2655,7 @@ def set_ymargin(self, m):
2654
2655
if m <= - 0.5 :
2655
2656
raise ValueError ("margin must be greater than -0.5" )
2656
2657
self ._ymargin = m
2657
- self ._request_autoscale_view (scalex = False , scaley = True )
2658
+ self ._request_autoscale_view ("y" )
2658
2659
self .stale = True
2659
2660
2660
2661
def margins (self , * margins , x = None , y = None , tight = True ):
@@ -2771,7 +2772,8 @@ def autoscale(self, enable=True, axis='both', tight=None):
2771
2772
True turns autoscaling on, False turns it off.
2772
2773
None leaves the autoscaling state unchanged.
2773
2774
axis : {'both', 'x', 'y'}, default: 'both'
2774
- Which axis to operate on.
2775
+ The axis on which to operate. (For 3D axes, *axis* can also be set
2776
+ to 'z', and 'both' refers to all three axes.)
2775
2777
tight : bool or None, default: None
2776
2778
If True, first set the margins to zero. Then, this argument is
2777
2779
forwarded to `autoscale_view` (regardless of its value); see the
@@ -2793,7 +2795,10 @@ def autoscale(self, enable=True, axis='both', tight=None):
2793
2795
self ._xmargin = 0
2794
2796
if tight and scaley :
2795
2797
self ._ymargin = 0
2796
- self ._request_autoscale_view (tight = tight , scalex = scalex , scaley = scaley )
2798
+ if scalex :
2799
+ self ._request_autoscale_view ("x" , tight = tight )
2800
+ if scaley :
2801
+ self ._request_autoscale_view ("y" , tight = tight )
2797
2802
2798
2803
def autoscale_view (self , tight = None , scalex = True , scaley = True ):
2799
2804
"""
@@ -3309,8 +3314,8 @@ def locator_params(self, axis='both', tight=None, **kwargs):
3309
3314
Parameters
3310
3315
----------
3311
3316
axis : {'both', 'x', 'y'}, default: 'both'
3312
- The axis on which to operate.
3313
-
3317
+ The axis on which to operate. (For 3D axes, *axis* can also be
3318
+ set to 'z', and 'both' refers to all three axes.)
3314
3319
tight : bool or None, optional
3315
3320
Parameter passed to `~.Axes.autoscale_view`.
3316
3321
Default is None, for no change.
@@ -3332,15 +3337,12 @@ def locator_params(self, axis='both', tight=None, **kwargs):
3332
3337
ax.locator_params(tight=True, nbins=4)
3333
3338
3334
3339
"""
3335
- _api .check_in_list (['x' , 'y' , 'both' ], axis = axis )
3336
- update_x = axis in ['x' , 'both' ]
3337
- update_y = axis in ['y' , 'both' ]
3338
- if update_x :
3339
- self .xaxis .get_major_locator ().set_params (** kwargs )
3340
- if update_y :
3341
- self .yaxis .get_major_locator ().set_params (** kwargs )
3342
- self ._request_autoscale_view (tight = tight ,
3343
- scalex = update_x , scaley = update_y )
3340
+ _api .check_in_list ([* self ._axis_names , "both" ], axis = axis )
3341
+ for name in self ._axis_names :
3342
+ if axis in [name , "both" ]:
3343
+ loc = self ._get_axis_map ()[name ].get_major_locator ()
3344
+ loc .set_params (** kwargs )
3345
+ self ._request_autoscale_view (name , tight = tight )
3344
3346
self .stale = True
3345
3347
3346
3348
def tick_params (self , axis = 'both' , ** kwargs ):
0 commit comments