我一直在研究一个涉及行星围绕恒星的动画的 2 体问题。我希望我的星球在移动这样的东西时留下一点痕迹。除了这一件事,我的代码完美地绘制了所有内容。我无法得到这个星球的踪迹。
fig, ax = plt.subplots()
print(func(0.98, -np.pi, 0, 0, 0.001))
ax.set(xlim = (-1.2,1.5), ylim = (-1.5,1.5), xlabel = 'x axis', ylabel='y axis', title = 'Planet\'s orbit')
def polar_animator(i):
trail = 40
l1.set_data(x_graph[i-1:i], y_graph[i-1:i])
return l1,
l1, = ax.plot([],[], 'o-')
l2, = ax.plot([-0.8],[0],marker= 'o')
ani = animation.FuncAnimation(fig, polar_animator, frames= len(x_graph), interval=5, blit=True)
ani.save('planet.mp4', writer= 'ffmpeg')
我得到的输出只是一个围绕太阳移动的球。