plenoptic.plot.histogram#

plenoptic.plot.histogram(data, labels=None, batch_idx=0, channel_idx=None, ylim=False, xlim='range', xlabel='Values', ax=None, title='Histogram of tensor values', alpha=0.4, **kwargs)[source]#

Plot histogram of values from tensor.

Intended use for this is to plot distributions of pixel values.

Parameters:
  • data (Tensor | list[Tensor]) – The data to plot. Must either be a single tensor or a list of tensors.

  • labels (str | list[str] | None (default: None)) – Labels to use for legend. Must match data: if data is a single tensor, must be a single string; if data is a list of tensors, must be a list of the same length. If None, no legend is created.

  • batch_idx (int | None (default: 0)) – Which index to take from the batch (first) dimension. If None, we use all batches.

  • channel_idx (int | None (default: None)) – Which index to take from the channel (second) dimension. If None, we use all channels.

  • ylim (tuple[float, float] | Literal[False] (default: False)) – If tuple, the ylimit to set for this axis. If False, we leave it untouched.

  • xlim (tuple[float, float] | Literal[False, 'range'] (default: 'range')) – If "range", set the xlimits to the range across plotted data. If tuple, the xlimit to set for this axis. If False, we leave it untouched.

  • xlabel (str | Literal[False] (default: 'Values')) – Label to put on the x-axis.

  • ax (Axes | None (default: None)) – Pre-existing axes for plot. If None, we call matplotlib.pyplot.gca.

  • title (str (default: 'Histogram of tensor values')) – Title for the axis.

  • alpha (float (default: 0.4)) – Alpha value for the histogram bars.

  • **kwargs (Any) – Passed to matplotlib.pyplot.hist.

Return type:

Axes

Returns:

ax – Created axes.

Raises:

ValueError – If labels and data are both lists but have different lengths

See also

synthesis_histogram

Use this function to plot histogram of values from a synthesis object.

Examples

>>> import plenoptic as po
>>> import torch
>>> img = po.data.einstein()
>>> po.plot.histogram(img)
<Axes: ... 'Histogram of tensor values'...>

(png, hires.png, pdf)

../../_images/plenoptic-plot-histogram-1.png

Plot on an existing axis:

>>> fig, axes = plt.subplots(1, 2, figsize=(8, 4))
>>> po.plot.histogram(img, ax=axes[1])
<Axes: ... 'Histogram of tensor values'...>

(png, hires.png, pdf)

../../_images/plenoptic-plot-histogram-2.png