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

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make stackplot take an arbitrary number of args.
stackplot now supports taking either an MxN array of data, stacking
along axis=0, or an arbitrary number of 1xN arrays, stacking them in the
order passed.

No checks are done for the case when no the number of args is zero. An
exception should probably be raised here.

Updated docstring to explain new call signatures.
  • Loading branch information
dmcdougall committed Jun 19, 2012
commit 8bbac65f9495f487a6644f0480acce146b4d95ac
4 changes: 2 additions & 2 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6409,8 +6409,8 @@ def quiver(self, *args, **kw):
return q
quiver.__doc__ = mquiver.Quiver.quiver_doc

def stackplot(self, x, y):
return mstack.stackplot(self, x, y)
def stackplot(self, x, *args):
return mstack.stackplot(self, x, *args)
stackplot.__doc__ = mstack.stackplot.__doc__

def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
Expand Down
14 changes: 11 additions & 3 deletions lib/matplotlib/stackplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@
__all__ = ['stackplot']


def stackplot(axes, x, y):
def stackplot(axes, x, *args):
"""Draws a stacked area plot.

Parameters
----------
*x* : 1d array of dimension N
*y* : 2d array of dimension MxN. The data is assumed to be unstacked.
*y* : 2d array of dimension MxN, OR any number 1d arrays each of dimension
1xN. The data is assumed to be unstacked. Each of the following
calls is legal:

stackplot(x, y) # where y is MxN
staclplot(x, y1, y2, y3, y4) # where y1, y2, y3, y4, are all 1xN

Returns
-------
*r* : A list of `matplotlib.collections.PolyCollection`, one for each
element in the stacked area plot.
"""

y = np.atleast_2d(y)
if len(args) == 1:
y = np.atleast_2d(*args)
elif len(args) > 1:
y = np.row_stack(args)

# Assume data passed has not been 'stacked', so stack it here.
y_stack = np.cumsum(y, axis=0)
Expand Down