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

Skip to content

Commit 29b048f

Browse files
committed
Raise NotImplementedError when setting aspect on 3D axes
1 parent a276243 commit 29b048f

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Equal aspect axes for 3D plots disabled
2+
```````````````````````````````````````
3+
4+
Setting the aspect on 3D axes previously returned non-sensical
5+
results (e.g. see https://github.com/matplotlib/matplotlib/issues/1077).
6+
Calling ``ax.set_aspect('equal')`` or ``ax.set_aspect(num)``
7+
on a 3D axes now raises a ``NotImplementedError``.

lib/matplotlib/axes/_base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,11 +1271,18 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
12711271
if not (cbook._str_equal(aspect, 'equal')
12721272
or cbook._str_equal(aspect, 'auto')):
12731273
aspect = float(aspect) # raise ValueError if necessary
1274+
1275+
if (not cbook._str_equal(aspect, 'auto')) and self.name == '3d':
1276+
raise NotImplementedError(
1277+
'It is not currently possible to manually set the aspect '
1278+
'on 3D axes')
1279+
12741280
if share:
12751281
axes = set(self._shared_x_axes.get_siblings(self)
12761282
+ self._shared_y_axes.get_siblings(self))
12771283
else:
12781284
axes = [self]
1285+
12791286
for ax in axes:
12801287
ax._aspect = aspect
12811288

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
import numpy as np
1212

1313

14+
def test_aspect_equal_error():
15+
fig = plt.figure()
16+
ax = fig.add_subplot(111, projection='3d')
17+
with pytest.raises(NotImplementedError):
18+
ax.set_aspect('equal')
19+
20+
1421
@image_comparison(baseline_images=['bar3d'], remove_text=True)
1522
def test_bar3d():
1623
fig = plt.figure()

0 commit comments

Comments
 (0)