|
3 | 3 | Stem Plot
|
4 | 4 | =========
|
5 | 5 |
|
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. |
9 | 8 | """
|
10 | 9 | import matplotlib.pyplot as plt
|
11 | 10 | import numpy as np
|
12 | 11 |
|
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)) |
15 | 14 |
|
16 |
| -markerline, stemlines, baseline = plt.stem(x, np.cos(x), '-.') |
| 15 | +plt.stem(x, y) |
| 16 | +plt.show() |
17 | 17 |
|
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`. |
20 | 25 |
|
| 26 | +markerline, stemlines, baseline = plt.stem(x, y, linefmt='grey', markerfmt='D', |
| 27 | + bottom=1.1) |
| 28 | +markerline.set_markerfacecolor('none') |
21 | 29 | plt.show()
|
22 | 30 |
|
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