plenoptic.plot.plot_representation#

plenoptic.plot.plot_representation(model=None, data=None, ax=None, figsize=None, ylim=False, batch_idx=0, title='', as_rgb=False)[source]#

Plot model representation.

We try to plot data on ax, using the model.plot_representation method, if it has it, and otherwise use a function that makes sense based on the shape of data.

All of these arguments are optional, but at least some of them need to be set:

  • If model is None, we fall-back to a type of plot based on the shape of data. If it looks image-like, we’ll use imshow and if it looks vector-like, we’ll use stem_plot. If it’s a dictionary, we’ll assume each key, value pair gives the title and data to plot on a separate sub-plot.

  • If data is None, we can only do something if model.plot_representation has some behavior when data=None; this is probably to plot its own representation attribute. Thus, this will raise an Exception if both model and data are None, because we have no idea what to plot then.

  • If ax is None, we create a one-subplot figure using figsize. If ax is not None, we therefore ignore figsize.

  • If ylim is None, we set the axes’ y-limits to be (-y_max, y_max), where y_max=np.abs(data).max(). If it’s False, we do nothing.

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

  • data (ndarray | dict | None (default: None)) – The data to plot. See above for behavior if None.

  • ax (Axes | None (default: None)) – The axis to plot on. See above for behavior if None.

  • figsize (tuple[float, float] | None (default: None)) – The size of the figure to create. Must be None if ax is not None. If both figsize and ax are None, then we use figsize=(5, 5).

  • ylim (tuple[float, float] | None | Literal[False] (default: False)) – The y-limits to use for this plot. See above for behavior if None. If False, we do nothing. Ignored if data looks image-like.

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

  • title (str (default: '')) – The title to put above this axis. If you want no title, pass the empty string ("").

  • as_rgb (bool (default: False)) – Whether to consider the channels as encoding RGB(A) values. It will be ignored if the representation doesn’t look image-like or if the model has its own plot_representation_error() method. Else, it will be passed to imshow, see that method’s docstring for details.

Return type:

list[Axes]

Returns:

axes – List of created axes.

Raises:
  • ValueError – If both figsize and ax are not None.

  • ValueError – If data (or its values, if it’s a dict) are not 3 or 4 dimensional.

See also

metamer_representation_error

Plot representation error for a Metamer object at a specified iteration.

stem_plot

If model does not have a plot_representation method and its output is 3d, the function used to visualize its output.

imshow

If model does not have a plot_representation method and its output is 4d, the function used to visualize its output.