Version 3.1.2
matplotlib

Table of Contents

Related Topics

Stem Plot

stem plots vertical lines from a baseline to the y-coordinate and places a marker at the tip.

=========
Stem Plot
=========

`~.pyplot.stem` plots vertical lines from a baseline to the y-coordinate and
places a marker at the tip.
"""
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.1, 2 * np.pi, 41)
y = np.exp(np.sin(x))

plt.stem(x, y, use_line_collection=True)
plt.show()
Traceback (most recent call last):
  File "/build/matplotlib-mO9dyQ/matplotlib-3.1.2/examples/lines_bars_and_markers/stem_plot.py", line 1
    =========
    ^
SyntaxError: invalid syntax

The position of the baseline can be adapted using bottom. The parameters linefmt, markerfmt, and basefmt control basic format properties of the plot. However, in contrast to plot not all properties are configurable via keyword arguments. For more advanced control adapt the line objects returned by pyplot.

markerline, stemlines, baseline = plt.stem(
    x, y, linefmt='grey', markerfmt='D', bottom=1.1, use_line_collection=True)
markerline.set_markerfacecolor('none')
plt.show()

References

The use of the following functions, methods, classes and modules is shown in this example:

import matplotlib
matplotlib.pyplot.stem
matplotlib.axes.Axes.stem

Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery