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

Skip to content

Commit ad8f969

Browse files
committed
Normalize aspect="equal" to aspect=1 in the setter.
This avoids having to redo the normalization later. `aspect="equal"` is probably too widely used to be worth deprecating, but we can also deemphasize it in the docs.
1 parent f9084c1 commit ad8f969

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,18 +1216,17 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
12161216
12171217
Parameters
12181218
----------
1219-
aspect : {'auto', 'equal'} or num
1219+
aspect : {'auto'} or num
12201220
Possible values:
12211221
1222-
======== ================================================
1222+
======== =================================================
12231223
value description
1224-
======== ================================================
1225-
'auto' automatic; fill the position rectangle with data
1226-
'equal' same scaling from data to plot units for x and y
1227-
num a circle will be stretched such that the height
1228-
is num times the width. aspect=1 is the same as
1229-
aspect='equal'.
1230-
======== ================================================
1224+
======== =================================================
1225+
'auto' automatic; fill the position rectangle with data.
1226+
num a circle will be stretched such that the height
1227+
is *num* times the width. 'equal' is a synonym
1228+
for ``aspect=1``, i.e. same scaling for x and y.
1229+
======== =================================================
12311230
12321231
adjustable : None or {'box', 'datalim'}, optional
12331232
If not ``None``, this defines which parameter will be adjusted to
@@ -1262,15 +1261,15 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
12621261
matplotlib.axes.Axes.set_anchor
12631262
defining the position in case of extra space.
12641263
"""
1265-
if not (cbook._str_equal(aspect, 'equal')
1266-
or cbook._str_equal(aspect, 'auto')):
1264+
if cbook._str_equal(aspect, 'equal'):
1265+
aspect = 1
1266+
if not cbook._str_equal(aspect, 'auto'):
1267+
if self.name == '3d':
1268+
raise NotImplementedError(
1269+
'It is not currently possible to manually set the aspect '
1270+
'on 3D axes')
12671271
aspect = float(aspect) # raise ValueError if necessary
12681272

1269-
if (not cbook._str_equal(aspect, 'auto')) and self.name == '3d':
1270-
raise NotImplementedError(
1271-
'It is not currently possible to manually set the aspect '
1272-
'on 3D axes')
1273-
12741273
if share:
12751274
axes = {*self._shared_x_axes.get_siblings(self),
12761275
*self._shared_y_axes.get_siblings(self)}
@@ -1532,9 +1531,6 @@ def apply_aspect(self, position=None):
15321531
self._set_position(position, which='active')
15331532
return
15341533

1535-
if aspect == 'equal':
1536-
aspect = 1
1537-
15381534
fig_width, fig_height = self.get_figure().get_size_inches()
15391535
fig_aspect = fig_height / fig_width
15401536

lib/matplotlib/tests/test_axes.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5435,13 +5435,11 @@ def test_square_plot():
54355435
ax.axis('square')
54365436
xlim, ylim = ax.get_xlim(), ax.get_ylim()
54375437
assert np.diff(xlim) == np.diff(ylim)
5438-
assert ax.get_aspect() == 'equal'
5438+
assert ax.get_aspect() == 1
54395439
assert_array_almost_equal(
5440-
ax.get_position(original=True).extents,
5441-
np.array((0.125, 0.1, 0.9, 0.9)))
5440+
ax.get_position(original=True).extents, (0.125, 0.1, 0.9, 0.9))
54425441
assert_array_almost_equal(
5443-
ax.get_position(original=False).extents,
5444-
np.array((0.2125, 0.1, 0.8125, 0.9)))
5442+
ax.get_position(original=False).extents, (0.2125, 0.1, 0.8125, 0.9))
54455443

54465444

54475445
def test_no_None():

lib/mpl_toolkits/axes_grid1/axes_size.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,8 @@ def get_size(self, renderer):
8484

8585
def _get_axes_aspect(ax):
8686
aspect = ax.get_aspect()
87-
# when aspec is "auto", consider it as 1.
88-
if aspect in ('normal', 'auto'):
87+
if aspect == "auto":
8988
aspect = 1.
90-
elif aspect == "equal":
91-
aspect = 1
92-
else:
93-
aspect = float(aspect)
94-
9589
return aspect
9690

9791

0 commit comments

Comments
 (0)