Created
April 25, 2015 18:19
-
-
Save charlesreid1/355041fcf72eb209d33e to your computer and use it in GitHub Desktop.
Weibull Distribution for Nested Sunburst http://charlesreid1.github.io/dang-sunburst/breakdown/nest.html
This file contains 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 seaborn as sns | |
from numpy.random import weibull | |
Nsamples = 1e4 | |
# generate a weibull distribution | |
k=2 | |
x = weibull(k,(Nsamples,)) | |
partition1, binlocs1, _ = hist(x,10); | |
partition2, binlocs2, _ = hist(x,100); | |
# Now dump this to a JSON file | |
import json | |
tree = {} | |
tree['name'] = 'root' | |
tree['freq'] = sum(partition1[:])/Nsamples | |
children = [] | |
for c1 in range(len(partition1)): | |
child = {} | |
child['name'] = 'X%d'%(c1+1) | |
child['freq'] = partition1[c1]/Nsamples | |
grandchildren = [] | |
for c2 in range(len(partition2)): | |
if c2<((c1+1)*10): | |
grandchild = {} | |
grandchild['name'] = 'X%d-%d'%(c1+1,c2+1) | |
grandchild['freq'] = partition2[c2]/Nsamples | |
grandchildren.append(grandchild) | |
child['children'] = grandchildren | |
children.append(child) | |
tree['children'] = children | |
with open('sunburst_nest_tree.json','w') as f: | |
json.dump(tree,f,sort_keys=True,indent=4,separators=(',', ': ')) | |
print "Done printing nested tree JSON to file." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment