plenoptic.plot.update_plot#
- plenoptic.plot.update_plot(axes, data, model=None, batch_idx=0)[source]#
Update the information in some axes (for an animation).
This is used for creating an animation over time. In order to create the animation, we need to know how to update the matplotlib Artists, and this provides a simple way of doing that. It assumes the plot has been created by something like
plot_representation, which initializes all the artists.We can update stem plots, lines (as returned by
matplotlib.pyplot.plot), scatter plots, or images (RGB, RGBA, or grayscale).There are two modes for this:
Single axis:
axesis a single axis, which may contain multiple artists (all of the same type) to update.datashould be atorch.Tensorwith multiple channels (one per artist in the same order) or be a dictionary whose keys give the label(s) of the corresponding artist(s) and whose values aretorch.Tensor.Multiple axes:
axesis a list of axes, each of which contains a single artist to update (artists can be different types).datashould be atorch.Tensorwith multiple channels (one per axis in the same order) or a dictionary with the same number of keys asaxes, which we can iterate through in order, and whose values aretorch.Tensor.
In all cases,
dataTensors should be 3d (if the plot we’re updating is a line or stem plot) or 4d (if it’s an image or scatter plot).RGB(A) images are special, since we store that info along the channel dimension, so they only work with single-axis mode (which will only have a single artist, because that’s how imshow works).
If you have multiple axes, each with multiple artists you want to update, that’s too complicated for us, and so you should write a
model.update_plot()function which handles that (seeplenoptic.models.PortillaSimoncelli.update_plotfor an example).If
modelis set, we try to callmodel.update_plot()(which must also return artists). Ifmodeldoesn’t have anupdate_plotmethod, then we try to figure out how to update the axes ourselves, based on the shape of the data.- Parameters:
axes (
Axes|list[Axes]) – The axis or list of axes to update. We assume that these are the axes created byplot_representationand so contain artists in the correct order.model (
Module|None(default:None)) – A differentiable model that tells us how to plotdata. See above for behavior ifNone.batch_idx (
int(default:0)) – Which index to take from the batch dimension.
- Return type:
- Returns:
artists – A list of the artists used to update the information on the plots.
- Raises:
ValueError – If
data(or its values, if it’s adict) are not 3 or 4 dimensional.