我目前正在试验matplotbib FuncAnimation并尝试一些exmaples。 Everthing运行良好,但是,我通过带有anim.save(...)的ffmpeg制作视频,并且我没有让我的动画播放速度更快/更慢。无论是改变matplotlib FuncAnimation帧间隔
FuncAnimation(...,interval=x,...)
也不
anim.save(...,fps=x.)
对视频输出有任何影响。两者之间有什么区别('帧'/'fps'应该是'间隔',否?)?这里我简化代码:
import numpy as np
import matplotlib.animation as animation
import matplotlib.pyplot as plt
class Ball:
def __init__(self,initpos,initvel,radius,M):
self.pos=initpos
self.vel=initvel
self.radius=radius
self.M=M
def step(self,dt):
self.pos += self.vel*dt
self.vel[2] += -9.81*dt*self.M
initpos=np.array([5.0,5.0,10.0])
initvel=np.array([0.0,0.0,0.0])
radius=0.25
M=1
test_ball = Ball(initpos,initvel,radius,M)
dt=1./10
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection='3d')
pts = []
pts += ax.plot([], [], [], 'bo', c="blue")
def init():
for pt in pts:
pt.set_data([], [])
pt.set_3d_properties([])
return pts
def animate(i):
test_ball.step(dt)
for pt in pts:
pt.set_data(test_ball.pos[0],test_ball.pos[1])
pt.set_3d_properties(test_ball.pos[2])
pt.set_markersize(10)
return pts
anim = animation.FuncAnimation(fig, animate,init_func=init,frames=50,interval=1)
mywriter = animation.FFMpegWriter()
anim.save('mymovie.mp4',writer=mywriter,fps=10)
希望有人能帮助我。非常感谢。
PS:顺便说一下,我不知道还有
- 初始化funcion做什么,因为代码也完全不运行它,但它是在大多数INET-例子。
- 什么标记是一个ax.plot(...,'o',...)点。单位的半径?