Search code examples
pythonmatplotlibmatplotlib-3d

How to make axes a constant length


I'm trying to make n-body simulation in python, but I can't find anywhere how to make the axes constant in matplotlib.

Here is what i want to simulate: enter image description here

And here is how it looks like in my program: https://streamable.com/cdn9i8

I think you can clearly see the problem, the axes scale and points seem to remain in the same place.

I don't know matplotlib at all, and I just want to find a way to visualise what I've made.

plt.ion()
fig = plt.figure()

ax = fig.add_subplot(111,projection='3d')

for t in np.arange(0,10000,dt):
    update_coords()
    ax.scatter(coords[:, 0], coords[:, 1], coords[:, 2])
    plt.draw()
    plt.pause(0.02)
    ax.cla()

coords is a 3 by 3 matrix of coordinates of points and update_coords() does all the logic.


Solution

  • You might want to use ax.set_xlim([x_min,x_max]), and the same for the other axes, with some fixed value of x_min and x_max