@@ -2064,7 +2064,7 @@ def apply_aspect(self, position=None):
2064
2064
x1 = xc + Xsize / 2.0
2065
2065
self .set_xbound (x_trf .inverted ().transform ([x0 , x1 ]))
2066
2066
2067
- def axis (self , * args , emit = True , ** kwargs ):
2067
+ def axis (self , arg = None , * , emit = True , ** kwargs ):
2068
2068
"""
2069
2069
Convenience method to get or set some axis properties.
2070
2070
@@ -2122,37 +2122,34 @@ def axis(self, *args, emit=True, **kwargs):
2122
2122
matplotlib.axes.Axes.set_xlim
2123
2123
matplotlib.axes.Axes.set_ylim
2124
2124
"""
2125
- if len (args ) > 1 :
2126
- raise TypeError ("axis() takes 0 or 1 positional arguments but "
2127
- f"{ len (args )} were given" )
2128
- elif len (args ) == 1 and isinstance (args [0 ], (str , bool )):
2129
- s = args [0 ]
2130
- if s is True :
2131
- s = 'on'
2132
- if s is False :
2133
- s = 'off'
2134
- s = s .lower ()
2135
- if s == 'on' :
2125
+ if isinstance (arg , (str , bool )):
2126
+ if arg is True :
2127
+ arg = 'on'
2128
+ if arg is False :
2129
+ arg = 'off'
2130
+ arg = arg .lower ()
2131
+ if arg == 'on' :
2136
2132
self .set_axis_on ()
2137
- elif s == 'off' :
2133
+ elif arg == 'off' :
2138
2134
self .set_axis_off ()
2139
- elif s in ('equal' , 'tight' , 'scaled' , 'auto' , 'image' , 'square' ):
2135
+ elif arg in [
2136
+ 'equal' , 'tight' , 'scaled' , 'auto' , 'image' , 'square' ]:
2140
2137
self .set_autoscale_on (True )
2141
2138
self .set_aspect ('auto' )
2142
2139
self .autoscale_view (tight = False )
2143
- if s == 'equal' :
2140
+ if arg == 'equal' :
2144
2141
self .set_aspect ('equal' , adjustable = 'datalim' )
2145
- elif s == 'scaled' :
2142
+ elif arg == 'scaled' :
2146
2143
self .set_aspect ('equal' , adjustable = 'box' , anchor = 'C' )
2147
2144
self .set_autoscale_on (False ) # Req. by Mark Bakker
2148
- elif s == 'tight' :
2145
+ elif arg == 'tight' :
2149
2146
self .autoscale_view (tight = True )
2150
2147
self .set_autoscale_on (False )
2151
- elif s == 'image' :
2148
+ elif arg == 'image' :
2152
2149
self .autoscale_view (tight = True )
2153
2150
self .set_autoscale_on (False )
2154
2151
self .set_aspect ('equal' , adjustable = 'box' , anchor = 'C' )
2155
- elif s == 'square' :
2152
+ elif arg == 'square' :
2156
2153
self .set_aspect ('equal' , adjustable = 'box' , anchor = 'C' )
2157
2154
self .set_autoscale_on (False )
2158
2155
xlim = self .get_xlim ()
@@ -2163,13 +2160,12 @@ def axis(self, *args, emit=True, **kwargs):
2163
2160
self .set_ylim ([ylim [0 ], ylim [0 ] + edge_size ],
2164
2161
emit = emit , auto = False )
2165
2162
else :
2166
- raise ValueError (f"Unrecognized string { s !r} to axis; "
2163
+ raise ValueError (f"Unrecognized string { arg !r} to axis; "
2167
2164
"try 'on' or 'off'" )
2168
2165
else :
2169
- if len (args ) == 1 :
2170
- limits = args [0 ]
2166
+ if arg is not None :
2171
2167
try :
2172
- xmin , xmax , ymin , ymax = limits
2168
+ xmin , xmax , ymin , ymax = arg
2173
2169
except (TypeError , ValueError ) as err :
2174
2170
raise TypeError ('the first argument to axis() must be an '
2175
2171
'iterable of the form '
0 commit comments