|
3 | 3 | Step Demo
|
4 | 4 | =========
|
5 | 5 |
|
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 | +
|
7 | 13 | """
|
8 | 14 | import numpy as np
|
9 |
| -from numpy import ma |
10 | 15 | import matplotlib.pyplot as plt
|
11 | 16 |
|
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) |
15 | 19 |
|
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) |
17 | 22 |
|
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) |
20 | 25 |
|
21 |
| -y -= 0.5 |
22 | 26 | plt.step(x, y, where='post', label='post')
|
| 27 | +plt.plot(x, y, 'C2o', alpha=0.5) |
23 | 28 |
|
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:') |
32 | 30 | 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