FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add stairstep plotting functionality by dmcdougall · Pull Request #1068 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 10 additions & 0 deletions examples/pylab_examples/stairs_demo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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()
5 changes: 5 additions & 0 deletions lib/matplotlib/axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import matplotlib.quiver as mquiver
import matplotlib.scale as mscale
import matplotlib.stackplot as mstack
import matplotlib.stairs as mstairs
import matplotlib.streamplot as mstream
import matplotlib.table as mtable
import matplotlib.text as mtext
Expand Down Expand Up @@ -6415,6 +6416,10 @@ def stackplot(self, x, *args, **kwargs):
return mstack.stackplot(self, x, *args, **kwargs)
stackplot.__doc__ = mstack.stackplot.__doc__

def stairs(self, *args, **kwargs):
return mstairs.stairs(self, *args, **kwargs)
stairs.__doc__ = mstairs.stairs.__doc__

def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
minlength=0.1):
Expand Down
45 changes: 45 additions & 0 deletions lib/matplotlib/stairs.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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):

Copy link
Copy Markdown
Member

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 Quality

To be consistent with the rest of the code-base, I would change "axes" to "ax"

"""Draws a stairstep plot

Copy link
Copy Markdown
Member

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 Quality

Put the triple quote on its own line.


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