目前我正在研究两体问题,涉及行星围绕太阳的运动。为了做到这一点,为了制作动画,我使用了FuncAnimation
of matplotlib.animation
。在该代码中x_graph
和y_graph
包含运动的值。要完成一次旋转,帧必须为6282。但要做到这一点,输出需要花费大量时间才能完成,动画也不平滑
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')
请假设您已经有了x_图和y_图的值
目前没有回答
相关问题 更多 >
编程相关推荐