BaseFuncAnimator

class sunpy.visualization.animator.BaseFuncAnimator(data, slider_functions, slider_ranges, fig=None, interval=200, colorbar=False, button_func=None, button_labels=None, start_image_func=None, **kwargs)[source] [edit on github]

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.

  • 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.

  • button_func (list, optional) – A list of functions to map to the buttons. Defaults to None.

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] [edit on github]

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.

  • 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] [edit on github]

Change the slider label.

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

  • label (str) – The label to set.

plot_start_image(ax)[source] [edit on github]

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

matplotlib.image.AxesImage – An matplotlib.image.AxesImage object, the instance returned from matplotlib.pyplot.imshow.