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
dataonax, using themodel.plot_representationmethod, if it has it, and otherwise use a function that makes sense based on the shape ofdata.All of these arguments are optional, but at least some of them need to be set:
If
modelisNone, we fall-back to a type of plot based on the shape ofdata. If it looks image-like, we’ll useimshowand if it looks vector-like, we’ll usestem_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
dataisNone, we can only do something ifmodel.plot_representationhas some behavior whendata=None; this is probably to plot its ownrepresentationattribute. Thus, this will raise an Exception if bothmodelanddataareNone, because we have no idea what to plot then.If
axisNone, we create a one-subplot figure usingfigsize. Ifaxis notNone, we therefore ignorefigsize.If
ylimisNone, we set the axes’ y-limits to be(-y_max, y_max), wherey_max=np.abs(data).max(). If it’sFalse, we do nothing.
- Parameters:
model (
Module|None(default:None)) – A differentiable model that tells us how to plotdata. See above for behavior ifNone.data (
ndarray|dict|None(default:None)) – The data to plot. See above for behavior ifNone.ax (
Axes|None(default:None)) – The axis to plot on. See above for behavior ifNone.figsize (
tuple[float,float] |None(default:None)) – The size of the figure to create. Must beNoneif ax is notNone. If both figsize and ax areNone, then we usefigsize=(5, 5).ylim (
tuple[float,float] |None|Literal[False] (default:False)) – The y-limits to use for this plot. See above for behavior ifNone. IfFalse, we do nothing. Ignored ifdatalooks 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 toimshow, see that method’s docstring for details.
- Return type:
- Returns:
axes – List of created axes.
- Raises:
ValueError – If both
figsizeandaxare notNone.ValueError – If
data(or its values, if it’s adict) are not 3 or 4 dimensional.
See also
metamer_representation_errorPlot representation error for a
Metamerobject at a specified iteration.stem_plotIf
modeldoes not have aplot_representationmethod and its output is 3d, the function used to visualize its output.imshowIf
modeldoes not have aplot_representationmethod and its output is 4d, the function used to visualize its output.