Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f82fa8a

Browse files
committed
Update example Step Demo
1 parent 8466da0 commit f82fa8a

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

examples/lines_bars_and_markers/step_demo.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,29 @@
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
915
from numpy import ma
1016
import matplotlib.pyplot as plt
1117

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

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

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

21-
y -= 0.5
2227
plt.step(x, y, where='post', label='post')
28+
plt.plot(x, y, 'C2o', alpha=0.5)
2329

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-
32-
plt.show()
30+
plt.legend(title='Parameter where:')
31+
plt.show()

0 commit comments

Comments
 (0)