Skip to content

Commit 910f9fd

Browse files
authored
Merge pull request #13148 from timhoffm/example-step
Update example Step Demo
2 parents 8466da0 + 25bd493 commit 910f9fd

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ per-file-ignores =
146146
examples/lines_bars_and_markers/joinstyle.py: E402
147147
examples/lines_bars_and_markers/scatter_piecharts.py: E402
148148
examples/lines_bars_and_markers/span_regions.py: E402
149+
examples/lines_bars_and_markers/step_demo.py: E402
149150
examples/misc/agg_buffer.py: E402
150151
examples/misc/anchored_artists.py: E501
151152
examples/misc/contour_manual.py: E501

examples/lines_bars_and_markers/step_demo.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,42 @@
33
Step Demo
44
=========
55
6-
Example step plots.
6+
This example demonstrates the use of `.pyplot.step` for piece-wise constant
7+
curves. In particular, it illustrates the effect of the parameter *where*
8+
on the step position.
9+
10+
The circular markers created with `.pyplot.plot` show the actual data
11+
positions so that it's easier to see the effect of *where*.
12+
713
"""
814
import numpy as np
9-
from numpy import ma
1015
import matplotlib.pyplot as plt
1116

12-
x = np.arange(1, 7, 0.4)
13-
y0 = np.sin(x)
14-
y = y0.copy() + 2.5
17+
x = np.arange(14)
18+
y = np.sin(x / 2)
1519

16-
plt.step(x, y, label='pre (default)')
20+
plt.step(x, y + 2, label='pre (default)')
21+
plt.plot(x, y + 2, 'C0o', alpha=0.5)
1722

18-
y -= 0.5
19-
plt.step(x, y, where='mid', label='mid')
23+
plt.step(x, y + 1, where='mid', label='mid')
24+
plt.plot(x, y + 1, 'C1o', alpha=0.5)
2025

21-
y -= 0.5
2226
plt.step(x, y, where='post', label='post')
27+
plt.plot(x, y, 'C2o', alpha=0.5)
2328

24-
y = ma.masked_where((y0 > -0.15) & (y0 < 0.15), y - 0.5)
25-
plt.step(x, y, label='masked (pre)')
26-
27-
plt.legend()
28-
29-
plt.xlim(0, 7)
30-
plt.ylim(-0.5, 4)
31-
29+
plt.legend(title='Parameter where:')
3230
plt.show()
31+
32+
#############################################################################
33+
#
34+
# ------------
35+
#
36+
# References
37+
# """"""""""
38+
#
39+
# The use of the following functions, methods, classes and modules is shown
40+
# in this example:
41+
42+
import matplotlib
43+
matplotlib.axes.Axes.step
44+
matplotlib.pyplot.step

0 commit comments

Comments
 (0)