I am currently experimenting with the matplotbib FuncAnimation and try some exmaples. Everthing runs fine, however, I produce videos via ffmpeg with anim.save(...) and I don't get my animation to play faster/slower. Neither changing
FuncAnimation(...,interval=x,...)
nor
anim.save(...,fps=x.)
had any effect on the video output. What is the difference between the two ('frames'/'fps' should be 'interval', no?)? Here my reduced code:
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)
Hope, someone can help me. Thanks a lot.
PS: By the way, I was wondering as well
- what the init funcion does because the code also runs perfectly without it but it is in most of the inet-examples.
- what markersize is for an ax.plot(...,'o',...) point. Radius in which unit?