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 againstdata
. Defaults to-1
, i.e., the last dimension of the array.axis_ranges (
list
of physical coordinates for thenumpy.ndarray
, optional) – Defaults toNone
and array indices will be used for all axes. Thelist
should contain one element for each axis of thenumpy.ndarray
. For the image axes a[min, max]
pair should be specified which will be passed tomatplotlib.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.xlim (
tuple
, optional) – Limits of x-axis of plot. Defaults toNone
.ylim (
tuple
, optional) – Limits of y-axis of plot. Defaults toNone
.
Notes
Additional information on API of
axes_ranges
keyword argument.x-axis values must be supplied (if desired) as an array in the element of the
axis_ranges
list
corresponding to theplot_axis_index ``in the data array, i.e., ``x_axis_values == axis_ranges[plot_axis_index]
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.
The shape of the x-axis values array can take two forms.
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.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)
, whereplot_axis_index == 0
, the 0th frame of the animation will show data fromdata[:, 0]
with the x-axis described byaxis_ranges[plot_axis_index][:, 0]
, while the 1st frame will show data fromdata[:, 1]
with the x-axis described byaxis_ranges[plot_axis_index][:, 1]
.
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