Skip to content

Commit 5ca5e22

Browse files
authored
Merge pull request #13691 from meeseeksmachine/auto-backport-of-pr-13687-on-v3.1.x
Backport PR #13687 on branch v3.1.x (Update stem example)
2 parents 3014ebf + bed2a9c commit 5ca5e22

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ per-file-ignores =
143143
examples/lines_bars_and_markers/scatter_piecharts.py: E402
144144
examples/lines_bars_and_markers/scatter_with_legend.py: E402
145145
examples/lines_bars_and_markers/span_regions.py: E402
146+
examples/lines_bars_and_markers/stem_plot.py: E402
146147
examples/lines_bars_and_markers/step_demo.py: E402
147148
examples/misc/agg_buffer.py: E402
148149
examples/misc/anchored_artists.py: E501

examples/lines_bars_and_markers/stem_plot.py

+29-11
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,41 @@
33
Stem Plot
44
=========
55
6-
Stem plot plots vertical lines from baseline to the y-coordinate
7-
Plotting cosine(x) w.r.t x, using '-.' as the pattern
8-
for plotting vertical lines
6+
`~.pyplot.stem` plots vertical lines from a baseline to the y-coordinate and
7+
places a marker at the tip.
98
"""
109
import matplotlib.pyplot as plt
1110
import numpy as np
1211

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

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

18-
# setting property of baseline with color red and linewidth 2
19-
plt.setp(baseline, color='r', linewidth=2)
18+
#############################################################################
19+
#
20+
# The position of the baseline can be adapted using *bottom*.
21+
# The parameters *linefmt*, *markerfmt*, and *basefmt* control basic format
22+
# properties of the plot. However, in contrast to `~.pyplot.plot` not all
23+
# properties are configurable via keyword arguments. For more advanced
24+
# control adapt the line objects returned by `~.pyplot`.
2025

26+
markerline, stemlines, baseline = plt.stem(x, y, linefmt='grey', markerfmt='D',
27+
bottom=1.1)
28+
markerline.set_markerfacecolor('none')
2129
plt.show()
2230

23-
#############################
24-
# This example makes use of:
25-
# * :meth:`matplotlib.axes.Axes.stem`
31+
#############################################################################
32+
#
33+
# ------------
34+
#
35+
# References
36+
# """"""""""
37+
#
38+
# The use of the following functions, methods, classes and modules is shown
39+
# in this example:
40+
41+
import matplotlib
42+
matplotlib.pyplot.stem
43+
matplotlib.axes.Axes.stem

0 commit comments

Comments
 (0)