Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f6dd49

Browse files
Yunfei YangYunfei Yang
authored andcommitted
Made changes to square plot as suggested.
1 parent d6848b1 commit 3f6dd49

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,8 @@ def axis(self, *v, **kwargs):
13071307
self.set_axis_on()
13081308
elif s == 'off':
13091309
self.set_axis_off()
1310-
elif s in ('equal', 'tight', 'scaled', 'normal', 'auto', 'image', 'square'):
1310+
elif s in ('equal', 'tight', 'scaled', 'normal',
1311+
'auto', 'image', 'square'):
13111312
self.set_autoscale_on(True)
13121313
self.set_aspect('auto')
13131314
self.autoscale_view(tight=False)
@@ -1329,18 +1330,18 @@ def axis(self, *v, **kwargs):
13291330
self.set_autoscale_on(False)
13301331
xlim = self.get_xlim()
13311332
ylim = self.get_ylim()
1332-
minlim = min(xlim[0], ylim[0])
1333-
maxlim = max(xlim[1], ylim[1])
1334-
self.set_xlim([minlim, maxlim], emit=emit, auto=False)
1335-
self.set_ylim([minlim, maxlim], emit=emit, auto=False)
1336-
1333+
edge_size = max(np.diff(xlim), np.diff(ylim))
1334+
self.set_xlim([xlim[0], xlim[0] + edge_size],
1335+
emit=emit, auto=False)
1336+
self.set_ylim([ylim[0], ylim[0] + edge_size],
1337+
emit=emit, auto=False)
13371338
else:
13381339
raise ValueError('Unrecognized string %s to axis; '
13391340
'try on or off' % s)
13401341
xmin, xmax = self.get_xlim()
13411342
ymin, ymax = self.get_ylim()
13421343
return xmin, xmax, ymin, ymax
1343-
1344+
13441345
try:
13451346
v[0]
13461347
except IndexError:

lib/matplotlib/pyplot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,12 @@ def axis(*v, **kwargs):
14081408
14091409
The xmin, xmax, ymin, ymax tuple is returned
14101410
1411+
>>> axis('square')
1412+
1413+
changes the limits of the (*xmax*-*xmin*) and (*ymax*-*ymin*) of
1414+
the *x* and *y* axes to be the same, and have the same scaling,
1415+
resulting in a square plot
1416+
14111417
.. seealso::
14121418
14131419
:func:`xlim`, :func:`ylim`

0 commit comments

Comments
 (0)