Skip to content

Update example Step Demo #13148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ per-file-ignores =
examples/lines_bars_and_markers/joinstyle.py: E402
examples/lines_bars_and_markers/scatter_piecharts.py: E402
examples/lines_bars_and_markers/span_regions.py: E402
examples/lines_bars_and_markers/step_demo.py: E402
examples/misc/agg_buffer.py: E402
examples/misc/anchored_artists.py: E501
examples/misc/contour_manual.py: E501
Expand Down
46 changes: 29 additions & 17 deletions examples/lines_bars_and_markers/step_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,42 @@
Step Demo
=========

Example step plots.
This example demonstrates the use of `.pyplot.step` for piece-wise constant
curves. In particular, it illustrates the effect of the parameter *where*
on the step position.

The circular markers created with `.pyplot.plot` show the actual data
positions so that it's easier to see the effect of *where*.

"""
import numpy as np
from numpy import ma
import matplotlib.pyplot as plt

x = np.arange(1, 7, 0.4)
y0 = np.sin(x)
y = y0.copy() + 2.5
x = np.arange(14)
y = np.sin(x / 2)

plt.step(x, y, label='pre (default)')
plt.step(x, y + 2, label='pre (default)')
plt.plot(x, y + 2, 'C0o', alpha=0.5)

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

y -= 0.5
plt.step(x, y, where='post', label='post')
plt.plot(x, y, 'C2o', alpha=0.5)

y = ma.masked_where((y0 > -0.15) & (y0 < 0.15), y - 0.5)
plt.step(x, y, label='masked (pre)')

plt.legend()

plt.xlim(0, 7)
plt.ylim(-0.5, 4)

plt.legend(title='Parameter where:')
plt.show()

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods, classes and modules is shown
# in this example:

import matplotlib
matplotlib.axes.Axes.step
matplotlib.pyplot.step