8000 BUG: Fix the aspect ratio of 3d plots · matplotlib/matplotlib@1d4a513 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d4a513

Browse files
committed
BUG: Fix the aspect ratio of 3d plots
Fixes gh-8894, by always using a "position" that maintains a uniform coordinate system. Test added - when viewed from above, the plot should be square not rhombic.
1 parent 9fab0bd commit 1d4a513

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+26
-0
lines changed
Lines changed: 5 additions & 0 deletions

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ def tunit_edges(self, vals=None, M=None):
266266
(tc[7], tc[4])]
267267
return edges
268268

269+
def apply_aspect(self, position=None):
270+
if position is None:
271+
position = self.get_position(original=True)
272+
273+
# in the superclass, we would go through and actually deal with axis
274+
# scales and box/datalim. Those are all irrelevant - all we need to do
275+
# is make sure our coordinate system is square.
276+
figW, figH = self.get_figure().get_size_inches()
277+
fig_aspect = figH / figW
278+
box_aspect = 1
279+
pb = position.frozen()
280+
pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect)
281+
self.set_position(pb1.anchored(self.get_anchor(), pb), 'active')
282+
269283
@artist.allow_rasterization
270284
def draw(self, renderer):
271285
# draw the background patch
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,13 @@ def test_axes3d_cla():
503503
ax.cla() # make sure the axis displayed is 3D (not 2D)
504504

505505

506+
@image_comparison(baseline_images=['axes3d_rotated'], extensions=['png'])
507+
def test_axes3d_rotated():
508+
fig = plt.figure()
509+
ax = fig.add_subplot(1, 1, 1, projection='3d')
510+
ax.view_init(90, 45) # look down, rotated. Should be square
511+
512+
506513
def test_plotsurface_1d_raises():
507514
x = np.linspace(0.5, 10, num=100)
508515
y = np.linspace(0.5, 10, num=100)

0 commit comments

Comments
 (0)
0