| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import numpy as np | ||
| from matplotlib import pyplot as plt | ||
|
|
||
| x = np.linspace(-2*np.pi, 2*np.pi, num=40, endpoint=True) | ||
| y = np.sin(x) | ||
|
|
||
| fig = plt.figure() | ||
| ax = fig.add_subplot(1, 1, 1) | ||
| ax.stairs(x, y) | ||
| plt.show() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """ | ||
| Stairstep plots. | ||
| """ | ||
|
|
||
| import numpy as np | ||
|
|
||
| __all__ = ['stairs'] | ||
|
|
||
| def stairs(axes, *args, **kwargs): | ||
| """Draws a stairstep plot | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityPut the triple quote on its own line.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| Parameters | ||
| ---------- | ||
| Takes either one or two arguments. Valid calls are: | ||
|
|
||
| ax.stairs(y) # Make a stairstep plot of the values in *y* | ||
| ax.stairs(x, y) # Stairstep plot of the values in *y* at points in *x* | ||
|
|
||
| *x*, *y* : 1d arrays. | ||
|
|
||
| Returns | ||
| ------- | ||
| *lines* : :class:`~matplotlib.collections.LineCollection` | ||
| Line collection defining all the steps in the stairstep plot | ||
| """ | ||
|
|
||
| if len(args) == 1: | ||
| y = np.asarray(args[0]) | ||
| x = np.arange(len(y)) | ||
| elif len(args) == 2: | ||
| x = np.asarray(args[0]) | ||
| y = np.asarray(args[1]) | ||
| else: | ||
| raise ValueError, "stairs takes either 1 or 2 arguments, %d given" % len(args) | ||
|
|
||
| d = 0.5 * np.abs(np.diff(x)) | ||
| dm = np.append(d[0], d) | ||
| dp = np.append(d, d[-1]) | ||
|
|
||
| xm = x - dm | ||
| xp = x + dp | ||
| x_all = np.dstack((xm, x, xp)).flatten() | ||
| y_all = np.dstack((y, y, y)).flatten() | ||
|
|
||
| return axes.plot(x_all, y_all, **kwargs) | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityTo be consistent with the rest of the code-base, I would change "axes" to "ax"
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.