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