所以我是Python新手,一直在尝试用matplotlib中的动画来模拟地球和月球的运动,动画效果很好,但它永远不会真正结束,有没有一种简单的方法可以做到这一点?代码如下:
def animate(i):
orbits()
ax1.clear()
plt.axis('equal')
ax1.plot(xMlist, yMlist)
ax2.plot(xElist, yElist)
ani = animation.FuncAnimation(fig, animate,frames=10, interval=1)
plt.show()
就像我说的,我对 python 还比较陌生,所以如果这是一个简单的答案,我真的很抱歉,但我到处都看了,尝试过的方法似乎都不起作用,例如设置帧数并没有改变任何东西,所以我不知所措真的。
最佳答案
您可以将重复参数设置为 false: https://matplotlib.org/api/_as_gen/matplotlib.animation.FuncAnimation.html
ani = animation.FuncAnimation(fig, animate,frames=10, interval=1,repeat=False)
因此,当您超出框架时,它就会停止。
关于python - 如何在 matplotlib 中停止动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50024509/