Skip to content

Instantly share code, notes, and snippets.

@charlesreid1
Created April 25, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesreid1/355041fcf72eb209d33e to your computer and use it in GitHub Desktop.
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
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