0

Currently I am working on 2 body problem which involves the motion of planet around the sun. In order to do so, in order to do animation I've used FuncAnimation of matplotlib.animation. In this code x_graph and y_graph contains the values for the motion. To complete one revolution, the frames has to be 6282. But in order to do so, the output takes a lot of time to complete and the animation is also not smooth.

fig = plt.figure()
p1 = fig.add_subplot(111)

l1, = p1.plot([],[])
l2, = p1.plot([-0.8],[0],marker= 'o')

print(func(0.98, -np.pi, 0, 0, 0.001))

plt.xlim(-1.2,1.5)
plt.ylim(-1.5,1.5)
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.title('Planet\'s orbit')

def polar_animator(i):
    l1.set_data(x_graph[:i], y_graph[:i])
    return l1,
    
ani = animation.FuncAnimation(fig, polar_animator, frames= len(x_graph), interval=1, blit=True)
ani.save('planet.mp4', writer= 'ffmpeg')

Please assume that you already have values for x_graph and y_graph

  • Can you try increasing the value of `interval`? As it is playing one frame every millisecond and displays can't play that fast motion (1000fps) so it could be possible that you are seeing skips in the motion. – ranka47 Dec 07 '20 at 20:58
  • @ranka47 I thought that if I decrease interval, it will give a smoother graph as well will take lesser time – QuantumOscillator Dec 07 '20 at 21:02
  • Yeah. But your screen should be able to display that. Generally they refresh at 60 frames per second, i.e, one new frame every 1/60 second >> 1/1000. – ranka47 Dec 07 '20 at 21:10
  • @ranka47 I tried what you said but this decreases the speed of the planet. I increased interval to 20 ms. It takes a whole minute to complete one revolution. That is too slow. I have seen people doing pretty smooth animations. For instance [Check this link](https://www.instagram.com/p/B_sCllahtjZ/) – QuantumOscillator Dec 07 '20 at 21:19
  • See if this helps, https://github.com/zaman13/Three-Body-Problem-Gravitational-System/blob/master/Python%20script/Earth_Jupiter_Sun_system.py. Can you add the x_graph and y_graph so that I can simulate? – ranka47 Dec 07 '20 at 21:56
  • @ranka47 where should I add the values? – QuantumOscillator Dec 07 '20 at 22:38

0 Answers0