@@ -2072,7 +2072,7 @@ def apply_aspect(self, position=None):
20722072 x1 = xc + Xsize / 2.0
20732073 self .set_xbound (x_trf .inverted ().transform ([x0 , x1 ]))
20742074
2075- def axis (self , * args , emit = True , ** kwargs ):
2075+ def axis (self , arg = None , / , * , emit = True , ** kwargs ):
20762076 """
20772077 Convenience method to get or set some axis properties.
20782078
@@ -2130,37 +2130,34 @@ def axis(self, *args, emit=True, **kwargs):
21302130 matplotlib.axes.Axes.set_xlim
21312131 matplotlib.axes.Axes.set_ylim
21322132 """
2133- if len (args ) > 1 :
2134- raise TypeError ("axis() takes 0 or 1 positional arguments but "
2135- f"{ len (args )} were given" )
2136- elif len (args ) == 1 and isinstance (args [0 ], (str , bool )):
2137- s = args [0 ]
2138- if s is True :
2139- s = 'on'
2140- if s is False :
2141- s = 'off'
2142- s = s .lower ()
2143- if s == 'on' :
2133+ if isinstance (arg , (str , bool )):
2134+ if arg is True :
2135+ arg = 'on'
2136+ if arg is False :
2137+ arg = 'off'
2138+ arg = arg .lower ()
2139+ if arg == 'on' :
21442140 self .set_axis_on ()
2145- elif s == 'off' :
2141+ elif arg == 'off' :
21462142 self .set_axis_off ()
2147- elif s in ('equal' , 'tight' , 'scaled' , 'auto' , 'image' , 'square' ):
2143+ elif arg in [
2144+ 'equal' , 'tight' , 'scaled' , 'auto' , 'image' , 'square' ]:
21482145 self .set_autoscale_on (True )
21492146 self .set_aspect ('auto' )
21502147 self .autoscale_view (tight = False )
2151- if s == 'equal' :
2148+ if arg == 'equal' :
21522149 self .set_aspect ('equal' , adjustable = 'datalim' )
2153- elif s == 'scaled' :
2150+ elif arg == 'scaled' :
21542151 self .set_aspect ('equal' , adjustable = 'box' , anchor = 'C' )
21552152 self .set_autoscale_on (False ) # Req. by Mark Bakker
2156- elif s == 'tight' :
2153+ elif arg == 'tight' :
21572154 self .autoscale_view (tight = True )
21582155 self .set_autoscale_on (False )
2159- elif s == 'image' :
2156+ elif arg == 'image' :
21602157 self .autoscale_view (tight = True )
21612158 self .set_autoscale_on (False )
21622159 self .set_aspect ('equal' , adjustable = 'box' , anchor = 'C' )
2163- elif s == 'square' :
2160+ elif arg == 'square' :
21642161 self .set_aspect ('equal' , adjustable = 'box' , anchor = 'C' )
21652162 self .set_autoscale_on (False )
21662163 xlim = self .get_xlim ()
@@ -2171,13 +2168,12 @@ def axis(self, *args, emit=True, **kwargs):
21712168 self .set_ylim ([ylim [0 ], ylim [0 ] + edge_size ],
21722169 emit = emit , auto = False )
21732170 else :
2174- raise ValueError (f"Unrecognized string { s !r} to axis; "
2171+ raise ValueError (f"Unrecognized string { arg !r} to axis; "
21752172 "try 'on' or 'off'" )
21762173 else :
2177- if len (args ) == 1 :
2178- limits = args [0 ]
2174+ if arg is not None :
21792175 try :
2180- xmin , xmax , ymin , ymax = limits
2176+ xmin , xmax , ymin , ymax = arg
21812177 except (TypeError , ValueError ) as err :
21822178 raise TypeError ('the first argument to axis() must be an '
21832179 'iterable of the form '
0 commit comments