Inheritance diagram for mpltools.animation:
Animation class.
This implementation is a interface for Matplotlib’s FuncAnimation class, but with different interface for:
Bases: object
Base class to create animation objects.
To create an animation, simply subclass Animation and override the __init__ method to create a plot (self.fig needs to be assigned to the figure object here), and override update with a generator that updates the plot:
class RandomPoints(Animation):
def __init__(self, width=10):
self.fig, self.ax = plt.subplots()
self.width = width
self.ax.axis([0, width, 0, width])
self.num_frames = 20
def update(self):
artists = []
self.ax.lines = [] # Clean up plot when repeating animation.
for i in np.arange(self.num_frames):
x, y = np.random.uniform(0, self.width, size=2)
artists.append(self.ax.plot(x, y, 'ro'))
yield artists
pts = RandomPoints()
pts.animate()
Note: if you want to use blitting (see docstring for Animation.animate), You must yield a sequence of artists in update.
This Animation class does not subclass any of Matplotlib’s animation classes because the __init__ method takes arguments for creating the plot, while animate method is what accepts arguments that alter the animation.
Methods
animate(**kwargs) | Run animation. |
init_background() | Initialize background artists. |
save(filename, **kwargs) | Saves a movie file by drawing every frame. |
update() | Update frame. |
Initialize plot for animation.
Replace this method to initialize the plot. The only requirement is that you must create a figure object assigned to self.fig.
Run animation.
Parameters : | interval : float, defaults to 200
repeat : {True | False}
repeat_delay : None
blit : {False | True}
init_background : function
save_count : int
|
---|
Initialize background artists.
Note: This method is passed to FuncAnimation as init_func.
Saves a movie file by drawing every frame.
Parameters : | filename : str
writer : matplotlib.animation.MovieWriter or str
fps : float
dpi : int
codec : :
bitrate : int
extra_args : list
metadata : dict
|
---|