Matplotlib animation duration

the code below shows and saves the animation of random matrices in a row. My question is how to set how long the animation saves. The only parameters that I have here, fps, etc., First, determine how many seconds the frame remains, and the second controls the image quality. I want to actually control the number of frames to be saved , in terms of matrices, the number of which is actually saved.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig = plt.figure()

N = 5

A = np.random.rand(N,N)
im = plt.imshow(A)

def updatefig(*args):
    im.set_array(np.random.rand(N,N))
    return im,

ani = animation.FuncAnimation(fig, updatefig, interval=200, blit=True) 

ani.save('try_animation.mp4', fps=10, dpi=80) #Frame per second controls speed, dpi       controls the quality 
plt.show()

I am wondering if additional parameters need to be added. I tried to find a suitable one in the class documentation in matplotlib, but I was unsuccessful:

http://matplotlib.org/api/animation_api.html#module-matplotlib.animation

+3
2

, FuncAnimation frames, . ,

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig = plt.figure()

N = 5

A = np.random.rand(N,N)
im = plt.imshow(A)

def updatefig(*args):
    im.set_array(np.random.rand(N,N))
    return im,

ani = animation.FuncAnimation(fig, updatefig, frames=10, interval=200, blit=True) 

ani.save('try_animation.mp4', fps=10, dpi=80) #Frame per second controls speed, dpi       controls the quality 
plt.show()

10 .

+5

, , , . , .

tl/dr:

  • frames * (1 / fps) ( )
  • frames * interval / 1000 ( )

, .

, :

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation


fig = plt.figure(figsize=(16, 12))
ax = fig.add_subplot(111)
# You can initialize this with whatever
im = ax.imshow(np.random.rand(6, 10), cmap='bone_r', interpolation='nearest')


def animate(i):
    aux = np.zeros(60)
    aux[i] = 1
    image_clock = np.reshape(aux, (6, 10))
    im.set_array(image_clock)

ani = animation.FuncAnimation(fig, animate, frames=60, interval=1000)
ani.save('clock.mp4', fps=1.0, dpi=200)
plt.show()

, :

, , . 60 , , .

, , , : interval animation.FuncAnimation "fps" ani.save . , , - , .

60 , 1 . , . , , fps=0.5. , , interval=2000.

[ , ]

+5

All Articles