LineAnimator#

class mpl_animators.LineAnimator(data, plot_axis_index=-1, axis_ranges=None, ylabel=None, xlabel=None, xlim=None, ylim=None, aspect='auto', **kwargs)[source]#

Bases: ArrayAnimator

Create a matplotlib backend independent data explorer for 1D plots.

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.

Parameters:
  • data (numpy.ndarray) – The y-axis to be visualized.

  • plot_axis_index (int, optional) – The axis used to plot against data. Defaults to -1, i.e., the last dimension of the array.

  • axis_ranges (list of physical coordinates for the numpy.ndarray, optional) – Defaults to None and array indices will be used for all axes. The list should contain one element for each axis of the numpy.ndarray. For the image axes a [min, max] pair should be specified which will be passed to matplotlib.pyplot.imshow as an extent. For the slider axes a [min, max] pair can be specified or an array the same length as the axis which will provide all values for that slider. For more information, see the Notes section of this docstring.

  • xlabel (str, optional) – Label of x-axis. Defaults to None.

  • ylabel (str, optional) – Label of y-axis. Defaults to None.

  • xlim (tuple, optional) – Limits of x-axis of plot. Defaults to None.

  • ylim (tuple, optional) – Limits of y-axis of plot. Defaults to None.

Notes

Additional information on API of axes_ranges keyword argument.

  1. x-axis values must be supplied (if desired) as an array in the element of the axis_ranges list corresponding to the plot_axis_index ``in the data array, i.e., ``x_axis_values == axis_ranges[plot_axis_index]

  2. The x-axis values represent the edges of the pixels/bins along the plotted axis, not the centers. Therefore there must be 1 more x-axis value than there are data points along the x-axis.

  3. The shape of the x-axis values array can take two forms.

    1. First, it can have a length 1 greater than the length of the data array along the dimension corresponding to the x-axis, i.e., len(axis_ranges[plot_axis_index]) == len(data[plot_axis_index])+1. In this scenario the same x-axis values are used in every frame of the animation.

    2. Second, the x-axis array can have the same shape as the data array, with the exception of the plotted axis which, as above, must be 1 greater than the length of the data array along that dimension. In this scenario the x-axis is refreshed for each frame. For example, if data.shape == axis_ranges[plot_axis_index].shape == (4, 3), where plot_axis_index == 0, the 0th frame of the animation will show data from data[:, 0] with the x-axis described by axis_ranges[plot_axis_index][:, 0], while the 1st frame will show data from data[:, 1] with the x-axis described by axis_ranges[plot_axis_index][:, 1].

  4. This API holds for slider axes.

Extra keywords are passed to ArrayAnimator.

Methods Summary

plot_start_image(ax)

Sets up a plot of initial image.

update_plot(val, line, slider)

Updates plot based on slider/array dimension being iterated.

Methods Documentation

plot_start_image(ax)[source]#

Sets up a plot of initial image.

update_plot(val, line, slider)[source]#

Updates plot based on slider/array dimension being iterated.