matplotlib FuncAnimation frame interval -


i experimenting matplotbib funcanimation , try exmaples. everthing runs fine, however, produce videos via ffmpeg anim.save(...) , don't animation play faster/slower. neither changing

funcanimation(...,interval=x,...) 

nor

anim.save(...,fps=x.) 

had effect on video output. difference between 2 ('frames'/'fps' should 'interval', no?)? here reduced code:

import numpy np import matplotlib.animation animation import matplotlib.pyplot 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():     pt in pts:     pt.set_data([], [])     pt.set_3d_properties([])     return pts  def animate(i): test_ball.step(dt)  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, can me. lot.

ps: way, wondering

  1. what init funcion because code runs without in of inet-examples.
  2. what markersize ax.plot(...,'o',...) point. radius in unit?

here working example.

from mpl_toolkits.mplot3d import axes3d import matplotlib.animation animation import matplotlib.pyplot plt import numpy np   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., 5., 10.]) initvel = np.array([0., 0., 0.]) radius = .25 m, dt = 1, .1   test_ball = ball(initpos, initvel, radius, m)  fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))  pts = ax.plot([], [], [], 'bo', c='blue')   def init():     pt in pts:         pt.set_data([], [])         pt.set_3d_properties([])     ax.set_xlim3d(0, 1.5 * initpos[0])     ax.set_ylim3d(0, 1.5 * initpos[1])     ax.set_zlim3d(0, 1.5 * initpos[2])     return pts   def animate(i):     test_ball.step(dt)     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) mywriter = animation.ffmpegwriter(fps=10) anim.save('mymovie.mp4', writer=mywriter) 

when using custom writer need specify number of frame per second when creating writer.

you can check correct fps following command line

$ ffprobe mymovie.mp4 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -