diff --git a/.flake8 b/.flake8 index 4500550227d2..21e44dfea9d2 100644 --- a/.flake8 +++ b/.flake8 @@ -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 diff --git a/examples/lines_bars_and_markers/stem_plot.py b/examples/lines_bars_and_markers/stem_plot.py index 2a5ad4d401b7..3ea49c10b787 100644 --- a/examples/lines_bars_and_markers/stem_plot.py +++ b/examples/lines_bars_and_markers/stem_plot.py @@ -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