Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ per-file-ignores =
examples/lines_bars_and_markers/scatter_piecharts.py: E402
examples/lines_bars_and_markers/scatter_with_legend.py: E402
examples/lines_bars_and_markers/span_regions.py: E402
examples/lines_bars_and_markers/stem_plot.py: E402
examples/lines_bars_and_markers/step_demo.py: E402
examples/misc/agg_buffer.py: E402
examples/misc/anchored_artists.py: E501
Expand Down
40 changes: 29 additions & 11 deletions examples/lines_bars_and_markers/stem_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,41 @@
Stem Plot
=========

Stem plot plots vertical lines from baseline to the y-coordinate
Plotting cosine(x) w.r.t x, using '-.' as the pattern
for plotting vertical lines
`~.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

# returns 10 evenly spaced samples from 0.1 to 2*PI
x = np.linspace(0.1, 2 * np.pi, 10)
x = np.linspace(0.1, 2 * np.pi, 41)
y = np.exp(np.sin(x))

markerline, stemlines, baseline = plt.stem(x, np.cos(x), '-.')
plt.stem(x, y)
plt.show()

# setting property of baseline with color red and linewidth 2
plt.setp(baseline, color='r', linewidth=2)
#############################################################################
#
# 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 `~.pyplot.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)
markerline.set_markerfacecolor('none')
plt.show()

#############################
# This example makes use of:
# * :meth:`matplotlib.axes.Axes.stem`
#############################################################################
#
# ------------
#
# 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