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

Skip to content

Commit bbeb534

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 bbeb534

Some content is hidden

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

55 files changed

+20
-0
lines changed

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ def test_axes3d_cla():
502502
ax.set_axis_off()
503503
ax.cla() # make sure the axis displayed is 3D (not 2D)
504504

505+
@image_comparison(baseline_images=['axes3d_rotated'], extensions=['png'])
506+
def test_axes3d_rotated():
507+
# fixed in pull request 4553
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
505511

506512
def test_plotsurface_1d_raises():
507513
x = np.linspace(0.5, 10, num=100)

0 commit comments

Comments
 (0)
0