@@ -1301,26 +1301,67 @@ def apply_aspect(self, position=None):
1301
1301
self .set_xbound ((x0 , x1 ))
1302
1302
1303
1303
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
1308
1347
1309
- *kwargs* are passed on to :meth:`set_xlim` and
1310
- :meth:`set_ylim`
1311
1348
"""
1349
+
1312
1350
if len (v ) == 0 and len (kwargs ) == 0 :
1313
1351
xmin , xmax = self .get_xlim ()
1314
1352
ymin , ymax = self .get_ylim ()
1315
1353
return xmin , xmax , ymin , ymax
1316
1354
1355
+ emit = kwargs .get ('emit' , True )
1356
+
1317
1357
if len (v ) == 1 and is_string_like (v [0 ]):
1318
1358
s = v [0 ].lower ()
1319
1359
if s == 'on' :
1320
1360
self .set_axis_on ()
1321
1361
elif s == 'off' :
1322
1362
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' ):
1324
1365
self .set_autoscale_on (True )
1325
1366
self .set_aspect ('auto' )
1326
1367
self .autoscale_view (tight = False )
@@ -1337,15 +1378,23 @@ def axis(self, *v, **kwargs):
1337
1378
self .autoscale_view (tight = True )
1338
1379
self .set_autoscale_on (False )
1339
1380
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 )
1341
1391
else :
1342
1392
raise ValueError ('Unrecognized string %s to axis; '
1343
1393
'try on or off' % s )
1344
1394
xmin , xmax = self .get_xlim ()
1345
1395
ymin , ymax = self .get_ylim ()
1346
1396
return xmin , xmax , ymin , ymax
1347
1397
1348
- emit = kwargs .get ('emit' , True )
1349
1398
try :
1350
1399
v [0 ]
1351
1400
except IndexError :
0 commit comments