animatplot.Animation

class animatplot.Animation(blocks, timeline=None, fig=None)[source]

The foundation of all animations.

Parameters:
  • blocks (list of animatplot.animations.Block) – A list of blocks to be animated

  • timeline (Timeline or 1D array, optional) – If an array is passed in, it will be converted to a Timeline. If not given, a timeline will be created using the length of the first block.

  • fig (matplotlib figure, optional) – The figure that the animation is to occur on

animation

a matplotlib animation returned from FuncAnimation

Methods

__init__

add

Updates the animation object by adding additional blocks.

controls

Creates interactive controls for the animation

save

Saves an animation

save_gif

Saves the animation to a gif

timeline_slider

Creates a timeline slider.

toggle

Creates a play/pause button to start/stop the animation

__init__(blocks, timeline=None, fig=None)[source]
add(new)[source]

Updates the animation object by adding additional blocks.

The new blocks can be passed as a list, or as part of a second animaion. If passed as part of a new animation, the timeline of this new animation object will replace the old one.

Parameters:

new (amp.animation.Animation, or list of amp.block.Block objects) – Either blocks to add to animation instance, or another animation instance whose blocks should be combined with this animation.

controls(timeline_slider_args={}, toggle_args={})[source]

Creates interactive controls for the animation

Creates both a play/pause button, and a time slider at once

Parameters:
  • timeline_slider_args (Dict, optional) – A dictionary of arguments to be passed to timeline_slider()

  • toggle_args (Dict, optional) – A dictionary of argyments to be passed to toggle()

save(*args, **kwargs)[source]

Saves an animation

A wrapper around matplotlib.animation.Animation.save()

save_gif(filename)[source]

Saves the animation to a gif

A convenience function. Provided to let the user avoid dealing with writers - uses PillowWriter.

Parameters:

filename (str) – the name of the file to be created without the file extension

timeline_slider(text='Time', ax=None, valfmt=None, color=None)[source]

Creates a timeline slider.

Parameters:
  • text (str, optional) – The text to display for the slider. Defaults to ‘Time’

  • ax (matplotlib.axes.Axes, optional) – The matplotlib axes to attach the slider to.

  • valfmt (str, optional) – a format specifier used to print the time Defaults to ‘%s’ for datetime64, timedelta64 and ‘%1.2f’ otherwise.

  • color – The color of the slider.

toggle(ax=None)[source]

Creates a play/pause button to start/stop the animation

Parameters:

ax (matplotlib.axes.Axes, optional) – The matplotlib axes to attach the button to.