BaseFuncAnimator#

class mpl_animators.BaseFuncAnimator(data, slider_functions, slider_ranges, fig=None, interval=200, colorbar=False, button_func=None, button_labels=None, start_image_func=None, slider_labels=None, **kwargs)[source]#

Bases: object

Create a Matplotlib backend independent data explorer which allows definition of figure update functions for each slider.

The following keyboard shortcuts are defined in the viewer:

  • ‘left’: previous step on active slider.

  • ‘right’: next step on active slider.

  • ‘top’: change the active slider up one.

  • ‘bottom’: change the active slider down one.

  • ‘p’: play/pause active slider.

This viewer can have user defined buttons added by specifying the labels and functions called when those buttons are clicked as keyword arguments.

To make this class useful the subclass must implement _plot_start_image which must define a self.im attribute which is an instance of matplotlib.image.AxesImage.

Parameters:
  • data (iterable) – Some arbitrary data.

  • slider_functions (list) – A list of functions to call when that slider is changed. These functions will have val, the axes image object and the slider widget instance passed to them, e.g., update_slider(val, im, slider)

  • slider_ranges (list) – A list of [min,max] pairs to set the ranges for each slider or an array of values for all points of the slider. (The slider update function decides which to support.)

  • fig (matplotlib.figure.Figure, optional) – Figure to use. Defaults to None, in which case a new figure is created.

  • interval (int, optional) – Animation interval in milliseconds. Defaults to 200.

  • colorbar (bool, optional) – Plot a colorbar. Defaults to False.

  • button_labels (list, optional) – A list of strings to label buttons. Defaults to None. If None and button_func is specified, it will default to the names of the functions.

  • button_func (list, optional) – A list of functions to map to the buttons. These functions are called with two arguments, (animator, event) where the first argument is the animator object, and the second is a matplotlib.backend_bases.MouseEvent object. Defaults to None.

  • slider_labels (list, optional) – A list of labels to draw in the slider, must be the same length as slider_functions.

fig#
Type:

matplotlib.figure.Figure

axes#
Type:

matplotlib.axes.Axes

Notes

Extra keywords are passed to matplotlib.pyplot.imshow.

Methods Summary

get_animation([axes, slider, startframe, ...])

Return a FuncAnimation instance for the selected slider.

label_slider(i, label)

Change the slider label.

plot_start_image(ax)

This method creates the initial image on the matplotlib.axes.Axes.

Methods Documentation

get_animation(axes=None, slider=0, startframe=0, endframe=None, stepframe=1, **kwargs)[source]#

Return a FuncAnimation instance for the selected slider.

This will allow easy saving of the animation to a file.

Parameters:
  • axes (matplotlib.axes.Axes, optional) – The matplotlib.axes.Axes to animate. Defaults to None, in which case the Axes associated with this animator are used. Passing a custom Axes can be useful if you want to create the animation on a custom figure that is not the figure set up by this Animator.

  • slider (int, optional) – The slider to animate along. Defaults to 0.

  • startframe (int, optional) – The frame to start the animation. Defaults to 0.

  • endframe (int, optional) – The frame to end the animation. Defaults to None.

  • stepframe (int, optional) – The step between frames. Defaults to 1.

Notes

Extra keywords are passed to matplotlib.animation.FuncAnimation.

label_slider(i, label)[source]#

Change the slider label.

Parameters:
  • i (int) – The index of the slider to change (0 is bottom).

  • label (str) – The label to set.

abstract plot_start_image(ax)[source]#

This method creates the initial image on the matplotlib.axes.Axes.

Warning

This method needs to be implemented in subclasses.

Parameters:

ax (matplotlib.axes.Axes) – This is the axes on which to plot the image.

Returns:

The matplotlib object to be animated, this is usually either a AxesImage object, or a Line2D.

Return type:

matplotlib.artist.Artist