@@ -1301,26 +1301,67 @@ def apply_aspect(self, position=None):
13011301 self .set_xbound ((x0 , x1 ))
13021302
13031303 def axis (self , * v , ** kwargs ):
1304- """
1305- Convenience method for manipulating the x and y view limits
1306- and the aspect ratio of the plot. For details, see
1307- :func:`~matplotlib.pyplot.axis`.
1304+ """Set axis properties.
1305+
1306+ Valid signatures::
1307+
1308+ xmin, xmax, ymin, ymax = axis()
1309+ xmin, xmax, ymin, ymax = axis(list_arg)
1310+ xmin, xmax, ymin, ymax = axis(string_arg)
1311+ xmin, xmax, ymin, ymax = axis(**kwargs)
1312+
1313+ Parameters
1314+ ----------
1315+ v : list of float or {'on', 'off', 'equal', 'tight', 'scaled',\
1316+ 'normal', 'auto', 'image', 'square'}
1317+ Optional positional argument
1318+
1319+ Axis data limits set from a list; or a command relating to axes:
1320+
1321+ ========== ================================================
1322+ Value Description
1323+ ========== ================================================
1324+ 'on' Toggle axis lines and labels on
1325+ 'off' Toggle axis lines and labels off
1326+ 'equal' Equal scaling by changing limits
1327+ 'scaled' Equal scaling by changing box dimensions
1328+ 'tight' Limits set such that all data is shown
1329+ 'auto' Automatic scaling, fill rectangle with data
1330+ 'normal' Same as 'auto'; deprecated
1331+ 'image' 'scaled' with axis limits equal to data limits
1332+ 'square' Square plot; similar to 'scaled', but initially\
1333+ forcing xmax-xmin = ymax-ymin
1334+ ========== ================================================
1335+
1336+ emit : bool, optional
1337+ Passed to set_{x,y}lim functions, if observers
1338+ are notified of axis limit change
1339+
1340+ xmin, ymin, xmax, ymax : float, optional
1341+ The axis limits to be set
1342+
1343+ Returns
1344+ -------
1345+ xmin, xmax, ymin, ymax : float
1346+ The axis limits
13081347
1309- *kwargs* are passed on to :meth:`set_xlim` and
1310- :meth:`set_ylim`
13111348 """
1349+
13121350 if len (v ) == 0 and len (kwargs ) == 0 :
13131351 xmin , xmax = self .get_xlim ()
13141352 ymin , ymax = self .get_ylim ()
13151353 return xmin , xmax , ymin , ymax
13161354
1355+ emit = kwargs .get ('emit' , True )
1356+
13171357 if len (v ) == 1 and is_string_like (v [0 ]):
13181358 s = v [0 ].lower ()
13191359 if s == 'on' :
13201360 self .set_axis_on ()
13211361 elif s == 'off' :
13221362 self .set_axis_off ()
1323- elif s in ('equal' , 'tight' , 'scaled' , 'normal' , 'auto' , 'image' ):
1363+ elif s in ('equal' , 'tight' , 'scaled' , 'normal' ,
1364+ 'auto' , 'image' , 'square' ):
13241365 self .set_autoscale_on (True )
13251366 self .set_aspect ('auto' )
13261367 self .autoscale_view (tight = False )
@@ -1337,15 +1378,23 @@ def axis(self, *v, **kwargs):
13371378 self .autoscale_view (tight = True )
13381379 self .set_autoscale_on (False )
13391380 self .set_aspect ('equal' , adjustable = 'box' , anchor = 'C' )
1340-
1381+ elif s == 'square' :
1382+ self .set_aspect ('equal' , adjustable = 'box' , anchor = 'C' )
1383+ self .set_autoscale_on (False )
1384+ xlim = self .get_xlim ()
1385+ ylim = self .get_ylim ()
1386+ edge_size = max (np .diff (xlim ), np .diff (ylim ))
1387+ self .set_xlim ([xlim [0 ], xlim [0 ] + edge_size ],
1388+ emit = emit , auto = False )
1389+ self .set_ylim ([ylim [0 ], ylim [0 ] + edge_size ],
1390+ emit = emit , auto = False )
13411391 else :
13421392 raise ValueError ('Unrecognized string %s to axis; '
13431393 'try on or off' % s )
13441394 xmin , xmax = self .get_xlim ()
13451395 ymin , ymax = self .get_ylim ()
13461396 return xmin , xmax , ymin , ymax
13471397
1348- emit = kwargs .get ('emit' , True )
13491398 try :
13501399 v [0 ]
13511400 except IndexError :
0 commit comments