Created
November 9, 2012 19:54
-
-
Save Tillsten/4047834 to your computer and use it in GitHub Desktop.
Steamgraph in mpl
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
| import numpy as np | |
| import random as r | |
| import matplotlib.pyplot as plt | |
| def layers(n, m): | |
| 'function to generate some data' | |
| def bump(a): | |
| x = 1 / (.1 + r.random()) | |
| y = 2 * r.random() - .5 | |
| z = 10 / (.1+ r.random()) | |
| for i in range(m): | |
| w = (i / float(m) - y) * z | |
| a[i] += x * np.exp(-w*w) | |
| a=np.zeros((m, n)) | |
| for i in range(n): | |
| for j in range(5): | |
| bump(a[:,i]) | |
| return a | |
| n=15 | |
| d=layers(n,500) | |
| #d_0=-np.sum(d,1)[:,None]*0.5 | |
| d_0=-1/(n+1.)*(d*(n-np.arange(1,n+1)[None,:]+1)).sum(1)[:,None] | |
| d_s=np.cumsum(d,1)+d_0 | |
| plt.figure() | |
| x=np.arange(d_s.shape[0]) | |
| c=plt.cm.coolwarm(np.linspace(0.1,0.5,n+1)) | |
| plt.fill_between(x, d_0.flat, d_s[:,0], interpolate=True,color=c[0]) | |
| for i in range(d_s.shape[1]-1): | |
| plt.fill_between(x,d_s[:,i],d_s[:,i+1], color=c[i+1], interpolate=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment