How to scale 3d axes
Asked Answered
L

2

28

I can't seem to find documentation regarding the ability to scale axes in a 3d image using matplotlib.

For example, I have the image:

3dplot And the axes have different scales. I would like them to be uniform.

Louisalouisburg answered 2/7, 2012 at 20:24 Comment(0)
V
57

Usually it is easiest for you to include some of the code that generated the image, so we can see what you've tried and also the general setup of your code. That being said, the inclusion of the following should work:

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt

fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlim3d(0, 1000)
ax.set_ylim3d(0, 1000)
ax.set_zlim3d(0, 1000)

Tested in python 3.11.2, matplotlib 3.7.1

fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(111, projection='3d')

ax.set_xlim3d(0, 1000)
ax.set_ylim3d(0, 1000)
ax.set_zlim3d(0, 1000)

enter image description here

Vintager answered 2/7, 2012 at 20:32 Comment(0)
S
6

The following sets the box aspect ratio from the current axes limits to achieve the "equal" behavior [source]:

ax.set_box_aspect([ub - lb for lb, ub in (getattr(ax, f'get_{a}lim')() for a in 'xyz')])
Suntan answered 6/12, 2021 at 12:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.