@@ -2099,28 +2099,34 @@ def axis(self, arg=None, /, *, emit=True, **kwargs):
2099
2099
"try 'on' or 'off'" )
2100
2100
else :
2101
2101
if arg is not None :
2102
- try :
2103
- xmin , xmax , ymin , ymax = arg
2104
- except (TypeError , ValueError ) as err :
2105
- raise TypeError ('the first argument to axis() must be an '
2106
- 'iterable of the form '
2107
- '[xmin, xmax, ymin, ymax]' ) from err
2102
+ if len (arg ) != 2 * len (self ._axis_names ):
2103
+ raise TypeError (
2104
+ "The first argument to axis() must be an iterable of the form "
2105
+ "[{}]" .format (", " .join (
2106
+ f"{ name } min, { name } max" for name in self ._axis_names )))
2107
+ limits = {
2108
+ name : arg [2 * i :2 * (i + 1 )]
2109
+ for i , name in enumerate (self ._axis_names )
2110
+ }
2108
2111
else :
2109
- xmin = kwargs .pop ('xmin' , None )
2110
- xmax = kwargs .pop ('xmax' , None )
2111
- ymin = kwargs .pop ('ymin' , None )
2112
- ymax = kwargs .pop ('ymax' , None )
2113
- xauto = (None # Keep autoscale state as is.
2114
- if xmin is None and xmax is None
2115
- else False ) # Turn off autoscale.
2116
- yauto = (None
2117
- if ymin is None and ymax is None
2118
- else False )
2119
- self .set_xlim (xmin , xmax , emit = emit , auto = xauto )
2120
- self .set_ylim (ymin , ymax , emit = emit , auto = yauto )
2112
+ limits = {}
2113
+ for name in self ._axis_names :
2114
+ ax_min = kwargs .pop (f'{ name } min' , None )
2115
+ ax_max = kwargs .pop (f'{ name } max' , None )
2116
+ limits [name ] = (ax_min , ax_max )
2117
+ for name , (ax_min , ax_max ) in limits .items ():
2118
+ ax_auto = (None # Keep autoscale state as is.
2119
+ if ax_min is None and ax_max is None
2120
+ else False ) # Turn off autoscale.
2121
+ set_ax_lim = getattr (self , f'set_{ name } lim' )
2122
+ set_ax_lim (ax_min , ax_max , emit = emit , auto = ax_auto )
2121
2123
if kwargs :
2122
2124
raise _api .kwarg_error ("axis" , kwargs )
2123
- return (* self .get_xlim (), * self .get_ylim ())
2125
+ lims = ()
2126
+ for name in self ._axis_names :
2127
+ get_ax_lim = getattr (self , f'get_{ name } lim' )
2128
+ lims += get_ax_lim ()
2129
+ return lims
2124
2130
2125
2131
def get_legend (self ):
2126
2132
"""Return the `.Legend` instance, or None if no legend is defined."""
0 commit comments