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: axes is a single axis, which may contain multiple artists (all of the same type) to update. data should be a torch.Tensor with 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 are torch.Tensor.

  • Multiple axes: axes is a list of axes, each of which contains a single artist to update (artists can be different types). data should be a torch.Tensor with multiple channels (one per axis in the same order) or a dictionary with the same number of keys as axes, which we can iterate through in order, and whose values are torch.Tensor.

In all cases, data Tensors 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 (see plenoptic.models.PortillaSimoncelli.update_plot for an example).

If model is set, we try to call model.update_plot() (which must also return artists). If model doesn’t have an update_plot method, 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 by plot_representation and so contain artists in the correct order.

  • data (Tensor | dict) – The new data to plot.

  • model (Module | None (default: None)) – A differentiable model that tells us how to plot data. See above for behavior if None.

  • batch_idx (int (default: 0)) – Which index to take from the batch dimension.

Return type:

list

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 a dict) are not 3 or 4 dimensional.