@@ -779,24 +779,26 @@ def viewLim(self):
779779 self ._unstale_viewLim ()
780780 return self ._viewLim
781781
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
795800 if tight is not None :
796801 self ._tight = tight
797- for k , v in want_scale .items ():
798- if v :
799- self ._stale_viewlims [k ] = True # Else keep old state.
800802
801803 def _set_lim_and_transforms (self ):
802804 """
@@ -2424,8 +2426,7 @@ def _unit_change_handler(self, axis_name, event=None):
24242426 for line in self .lines :
24252427 line .recache_always ()
24262428 self .relim ()
2427- self ._request_autoscale_view (scalex = (axis_name == "x" ),
2428- scaley = (axis_name == "y" ))
2429+ self ._request_autoscale_view (axis_name )
24292430
24302431 def relim (self , visible_only = False ):
24312432 """
@@ -2632,7 +2633,7 @@ def set_xmargin(self, m):
26322633 if m <= - 0.5 :
26332634 raise ValueError ("margin must be greater than -0.5" )
26342635 self ._xmargin = m
2635- self ._request_autoscale_view (scalex = True , scaley = False )
2636+ self ._request_autoscale_view ("x" )
26362637 self .stale = True
26372638
26382639 def set_ymargin (self , m ):
@@ -2654,7 +2655,7 @@ def set_ymargin(self, m):
26542655 if m <= - 0.5 :
26552656 raise ValueError ("margin must be greater than -0.5" )
26562657 self ._ymargin = m
2657- self ._request_autoscale_view (scalex = False , scaley = True )
2658+ self ._request_autoscale_view ("y" )
26582659 self .stale = True
26592660
26602661 def margins (self , * margins , x = None , y = None , tight = True ):
@@ -2771,7 +2772,8 @@ def autoscale(self, enable=True, axis='both', tight=None):
27712772 True turns autoscaling on, False turns it off.
27722773 None leaves the autoscaling state unchanged.
27732774 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.)
27752777 tight : bool or None, default: None
27762778 If True, first set the margins to zero. Then, this argument is
27772779 forwarded to `autoscale_view` (regardless of its value); see the
@@ -2793,7 +2795,10 @@ def autoscale(self, enable=True, axis='both', tight=None):
27932795 self ._xmargin = 0
27942796 if tight and scaley :
27952797 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 )
27972802
27982803 def autoscale_view (self , tight = None , scalex = True , scaley = True ):
27992804 """
@@ -3309,8 +3314,8 @@ def locator_params(self, axis='both', tight=None, **kwargs):
33093314 Parameters
33103315 ----------
33113316 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.)
33143319 tight : bool or None, optional
33153320 Parameter passed to `~.Axes.autoscale_view`.
33163321 Default is None, for no change.
@@ -3332,15 +3337,12 @@ def locator_params(self, axis='both', tight=None, **kwargs):
33323337 ax.locator_params(tight=True, nbins=4)
33333338
33343339 """
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 )
33443346 self .stale = True
33453347
33463348 def tick_params (self , axis = 'both' , ** kwargs ):
0 commit comments