plenoptic.plot.stem_plot#

plenoptic.plot.stem_plot(data, ax=None, title='', ylim=None, xvals=None, **kwargs)[source]#

Create a simple stem plot.

This plots the data, baseline, cleans up the axis, and sets the title.

Helper function for plot_representation.

If xvals=None, stem plot will have a baseline that covers the entire range of the data. In order to break that up visually (so there’s a line from 0 to 9, from 10 to 19, etc) pass xvals separately.

Parameters:
  • data (Tensor) – The data to plot (as a stem plot).

  • ax (Axes | None (default: None)) – The axis to plot the data on. If None, we plot on the current axis (grabbed with matplotlib.pyplot.gca).

  • title (str | None (default: '')) – The title to put on the axis. If None, we don’t call ax.set_title (useful if you want to avoid changing the title on an existing plot).

  • ylim (tuple | None | Literal[False] (default: None)) – If a tuple, the y-limits to use for this plot. If None, we use the original limits, slightly adjusted so that the minimum is 0. If False, we do not change y-limits.

  • xvals (tuple[list[float], list[float]] | None (default: None)) – A 2-tuple of lists, containing the start (xvals[0]) and stop (xvals[1]) x values for plotting. If None, baseline will cover full range.

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

Return type:

Axes

Returns:

ax – The axis with the plot.

Examples

We allow for breaks in the baseline value if we want to visually break up the plot, as we see below.

>>> import plenoptic as po
>>> import numpy as np
>>> # if ylim=None, as in this example, the minimum y-valuewill get
>>> # set to 0, so we want to make sure our values are all positive
>>> y = np.abs(np.random.randn(55))
>>> y[15:20] = np.nan
>>> y[35:40] = np.nan
>>> # we want to draw the baseline from 0 to 14, 20 to 34, and 40 to
>>> # 54, everywhere that we have non-NaN values for y
>>> xvals = ([0, 20, 40], [14, 34, 54])
>>> po.plot.stem_plot(y, xvals=xvals)
<Axes: >

(png, hires.png, pdf)

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

If we don’t care about breaking up the x-axis, you can set xvals=None. In this case, this function will just clean up the plot a little bit.

>>> # if ylim=None, as in this example, the minimum y-value will get
>>> # set to 0, so we want to make sure our values are all positive
>>> y = np.abs(np.random.randn(55))
>>> po.plot.stem_plot(y)
<Axes: >

(png, hires.png, pdf)

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