Mathplotlib 3d plot isn't perfectly square.

code:

def get_random_unit_vector():
    t = np.random.uniform(0.0, 2 * np.pi)
    sin_t, cos_t = np.sin(t), np.cos(t)

    z = np.random.uniform(-1.0, 1.0)
    z_height = np.sqrt(1.0 - z*z)

    return np.array([cos_t * z_height, sin_t * z_height, z])

random_vectors = [get_random_unit_vector() for _ in range(500)]

fig = plt.figure()
ax = plt.figure().add_subplot(projection='3d')

for v in random_vectors:
    ax.quiver(0, 0, 0, v[0], v[1], v[2])

# Set axis limits
ax.set_xlim([-1.5, 1.5])
ax.set_ylim([-1.5, 1.5])
ax.set_zlim([-1.5, 1.5])

plt.show()

why is one axis of the plot shorter than the other two?

Hi @Walter_Willness, this one should be pretty quick to resolve! ax.set_aspect('equal') will make things square for you, and check out the docs for a couple more options around it: mpl_toolkits.mplot3d.axes3d.Axes3D.set_aspect — Matplotlib 3.10.3 documentation