@@ -1610,7 +1610,7 @@ def apply_aspect(self, position=None):
1610
1610
else :
1611
1611
self .set_xbound ((x0 , x1 ))
1612
1612
1613
- def axis (self , * args , ** kwargs ):
1613
+ def axis (self , * args , emit = True , ** kwargs ):
1614
1614
"""
1615
1615
Convenience method to get or set some axis properties.
1616
1616
@@ -1624,8 +1624,7 @@ def axis(self, *args, **kwargs):
1624
1624
Parameters
1625
1625
----------
1626
1626
xmin, xmax, ymin, ymax : float, optional
1627
- The axis limits to be set. Either none or all of the limits must
1628
- be given. This can also be achieved using ::
1627
+ The axis limits to be set. This can also be achieved using ::
1629
1628
1630
1629
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
1631
1630
@@ -1665,16 +1664,13 @@ def axis(self, *args, **kwargs):
1665
1664
matplotlib.axes.Axes.set_xlim
1666
1665
matplotlib.axes.Axes.set_ylim
1667
1666
"""
1668
-
1669
- if len (args ) == len (kwargs ) == 0 :
1670
- xmin , xmax = self .get_xlim ()
1671
- ymin , ymax = self .get_ylim ()
1672
- return xmin , xmax , ymin , ymax
1673
-
1674
- emit = kwargs .get ('emit' , True )
1675
-
1676
- if len (args ) == 1 and isinstance (args [0 ], str ):
1677
- s = args [0 ].lower ()
1667
+ if len (args ) == 1 and isinstance (args [0 ], (str , bool )):
1668
+ s = args [0 ]
1669
+ if s is True :
1670
+ s = 'on'
1671
+ if s is False :
1672
+ s = 'off'
1673
+ s = s .lower ()
1678
1674
if s == 'on' :
1679
1675
self .set_axis_on ()
1680
1676
elif s == 'off' :
@@ -1714,45 +1710,36 @@ def axis(self, *args, **kwargs):
1714
1710
else :
1715
1711
raise ValueError ('Unrecognized string %s to axis; '
1716
1712
'try on or off' % s )
1717
- xmin , xmax = self .get_xlim ()
1718
- ymin , ymax = self .get_ylim ()
1719
- return xmin , xmax , ymin , ymax
1720
-
1721
- try :
1722
- args [0 ]
1723
- except IndexError :
1724
- xmin = kwargs .get ('xmin' , None )
1725
- xmax = kwargs .get ('xmax' , None )
1726
- auto = False # turn off autoscaling, unless...
1727
- if xmin is None and xmax is None :
1728
- auto = None # leave autoscaling state alone
1729
- xmin , xmax = self .set_xlim (xmin , xmax , emit = emit , auto = auto )
1730
-
1731
- ymin = kwargs .get ('ymin' , None )
1732
- ymax = kwargs .get ('ymax' , None )
1733
- auto = False # turn off autoscaling, unless...
1734
- if ymin is None and ymax is None :
1735
- auto = None # leave autoscaling state alone
1736
- ymin , ymax = self .set_ylim (ymin , ymax , emit = emit , auto = auto )
1737
- return xmin , xmax , ymin , ymax
1738
-
1739
- v = args [0 ]
1740
- if isinstance (v , bool ):
1741
- if v :
1742
- self .set_axis_on ()
1713
+ else :
1714
+ if len (args ) >= 1 :
1715
+ if len (args ) != 1 :
1716
+ cbook .warn_deprecated (
1717
+ "3.2" , message = "Passing more than one positional "
1718
+ "argument to axis() is deprecated and will raise a "
1719
+ "TypeError %(removal)s." )
1720
+ v = args [0 ]
1721
+ try :
1722
+ xmin , xmax , ymin , ymax = v
1723
+ except ValueError :
1724
+ raise ValueError ('args must contain [xmin xmax ymin ymax]' )
1743
1725
else :
1744
- self .set_axis_off ()
1745
- xmin , xmax = self .get_xlim ()
1746
- ymin , ymax = self .get_ylim ()
1747
- return xmin , xmax , ymin , ymax
1748
-
1749
- if len (v ) != 4 :
1750
- raise ValueError ('args must contain [xmin xmax ymin ymax]' )
1751
-
1752
- self .set_xlim ([v [0 ], v [1 ]], emit = emit , auto = False )
1753
- self .set_ylim ([v [2 ], v [3 ]], emit = emit , auto = False )
1754
-
1755
- return v
1726
+ xmin = kwargs .pop ('xmin' , None )
1727
+ xmax = kwargs .pop ('xmax' , None )
1728
+ ymin = kwargs .pop ('ymin' , None )
1729
+ ymax = kwargs .pop ('ymax' , None )
1730
+ xauto = (None # Keep autoscale state as is.
1731
+ if xmin is None and xmax is None
1732
+ else False ) # Turn off autoscale.
1733
+ yauto = (None
1734
+ if ymin is None and ymax is None
1735
+ else False )
1736
+ self .set_xlim (xmin , xmax , emit = emit , auto = xauto )
1737
+ self .set_ylim (ymin , ymax , emit = emit , auto = yauto )
1738
+ if kwargs :
1739
+ cbook .warn_deprecated (
1740
+ "3.1" , message = "Passing unsupported keyword arguments to "
1741
+ "axis() will raise a TypeError %(removal)s." )
1742
+ return (* self .get_xlim (), * self .get_ylim ())
1756
1743
1757
1744
def get_legend (self ):
1758
1745
"""Return the `Legend` instance, or None if no legend is defined."""
0 commit comments