Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Stackplot #818

Closed
wants to merge 8 commits into from

2 participants

@dmcdougall
Collaborator

Added new plot style: stackplot.

This addresses issue #359.
I've also added an example so you can try it out. If you don't want to try it out, I've attached the example output:

stackplot

Feedback always greatly appreciated.

@dmcdougall
Collaborator

Woah! Eight commits?!?? Anybody have any idea how I can fix this? Only the last two commits are relevant. The trisurf code was from and old pull request that was merged into master.

@tonysyu

You could use interactive rebasing---something like:

git rebase -i HEAD@{8}

And then, in the interactive prompt, change pick to squash (or just s), for everything below the top commit. You'll also have to force a push to your github repo after making these changes.

That said, it's generally frowned upon to rebase after pushing changes to a remote (where other people could have already forked your repo, and then the fork will be completely off after the rebase). I doubt it's much of an issue here, but I just thought I'd mention it.

@dmcdougall
Collaborator

Hmmm, but then the trisurf merge would still be there, right?

@tonysyu

Oh, so the trisurf merge adds code that you don't want to submit as part of the PR? In other words, you don't just want to collapse the commit message, but instead, ignore code-changes from those commits. Correct?

This stackoverflow response suggests creating a new branch based off of upstream/master and then cherry-picking the commits to add to the new branch (you'd replace the sha1 in the example with 3b383ee and ae76455). (Note: the response names the new branch upstream but you'd want to name it something else.) Also, you'd have to resubmit the PR using the new branch.

@dmcdougall
Collaborator
@dmcdougall
Collaborator

Alright, let's try this again. This time with a bajillion commits.

@dmcdougall dmcdougall closed this
@pelson pelson referenced this pull request
Closed

new plot style: stackplot #359

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 15, 2012
  1. @dmcdougall

    Merge branch 'trisurf'

    dmcdougall authored
    Conflicts:
    	CHANGELOG
  2. @dmcdougall

    Merge remote-tracking branch 'upstream/master'

    dmcdougall authored
    Conflicts:
    	CHANGELOG
Commits on Mar 17, 2012
  1. @dmcdougall
Commits on Mar 22, 2012
  1. @dmcdougall
Commits on Mar 28, 2012
  1. @dmcdougall
Commits on Apr 7, 2012
  1. @dmcdougall
  2. @dmcdougall

    Added new plot style to axes: stackplot.

    dmcdougall authored
    Stackplot adds the feature request in issue #359
    (matplotlib#359) and borrows
    heavily from Doug Y'barbo's stackoverflow answer
    (http://stackoverflow.com/questions/2225995/how-can-i-create-stacked-line-graph-with-matplotlib).
  3. @dmcdougall

    Added stackplot example.

    dmcdougall authored
This page is out of date. Refresh to see the latest.
View
11 examples/pylab_examples/stackplot_demo.py
@@ -0,0 +1,11 @@
+import numpy as np
+from matplotlib import pyplot as plt
+
+fnx = lambda : np.random.randint(5, 50, 10)
+y = np.row_stack((fnx(), fnx(), fnx()))
+x = np.arange(10)
+
+fig = plt.figure()
+ax = fig.add_subplot(111)
+ax.stackplot(x, y)
+plt.show()
View
5 lib/matplotlib/axes.py
@@ -29,6 +29,7 @@
import matplotlib.spines as mspines
import matplotlib.quiver as mquiver
import matplotlib.scale as mscale
+import matplotlib.stackplot as mstack
import matplotlib.streamplot as mstream
import matplotlib.table as mtable
import matplotlib.text as mtext
@@ -6382,6 +6383,10 @@ def quiver(self, *args, **kw):
return q
quiver.__doc__ = mquiver.Quiver.quiver_doc
+ def stackplot(self, x, y):
+ return mstack.stackplot(self, x, y)
+ stackplot.__doc__ = mstack.stackplot.__doc__
+
def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
cmap=None, arrowsize=1, arrowstyle='-|>', minlength=0.1):
if not self._hold: self.cla()
View
42 lib/matplotlib/stackplot.py
@@ -0,0 +1,42 @@
+"""
+Stacked area plot for 1D arrays inspired by Douglas Y'barbo's stackoverflow
+answer:
+http://stackoverflow.com/questions/2225995/how-can-i-create-stacked-line-graph-with-matplotlib
+
+(http://stackoverflow.com/users/66549/doug)
+
+"""
+import numpy as np
+import matplotlib
+
+__all__ = ['stackplot']
+
+
+def stackplot(axes, x, y):
+ """Draws a stacked area plot.
+
+ Parameters
+ ----------
+ *x* : 1d array of dimension N
+ *y* : 2d array of dimension MxN
+
+ Returns
+ -------
+ *r* : A list of `matplotlib.collections.PolyCollection`, one for each
+ element in the stacked area plot.
+ """
+
+ y = np.atleast_2d(y)
+
+ # Assume data passed has not been 'stacked', so stack it here.
+ y_stack = np.cumsum(y, axis=0)
+
+ r = []
+
+ # Color between x = 0 and the first array.
+ r.append(axes.fill_between(x, 0, y_stack[0,:], facecolor=axes._get_lines.color_cycle.next()))
+
+ # Color between array i-1 and array i
+ for i in xrange(len(y)-1):
+ r.append(axes.fill_between(x, y_stack[i-1,:], y_stack[i,:], facecolor=axes._get_lines.color_cycle.next()))
+ return r
Something went wrong with that request. Please try again.