import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D
Setting the aspect ratio works for 2d plots:
ax = plt.axes() ax.plot([0,1],[0,10]) ax.set_aspect('equal','box')
But does not for 3d:
ax = plt.axes(projection='3d') ax.plot([0,1],[0,1],[0,10]) ax.set_aspect('equal','box')
Is there a different syntax for the 3d case, or it's not implemented?
Matplotlib mplot3d toolkit One can rotate the 3D scene by simply clicking-and-dragging the scene. Zooming is done by right-clicking the scene and dragging the mouse up and down. Note that one does not use the zoom button like one would use for regular 2D plots.
As of matplotlib 3.3.0, Axes3D.set_box_aspect seems to be the recommended approach.
import numpy as np import matplotlib.pyplot as plt xs, ys, zs = ... ax = plt.axes(projection='3d') ax.set_box_aspect((np.ptp(xs), np.ptp(ys), np.ptp(zs))) # aspect ratio is 1:1:1 in data space ax.plot(xs, ys, zs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With