Created
August 21, 2013 02:25
-
-
Save jackparmer/6289734 to your computer and use it in GitHub Desktop.
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
#################################### | |
# Golden Spiral Heatmap Demo | |
# Questions? Email [email protected] | |
# For more docs, see plot.ly/api | |
#################################### | |
from numpy import * | |
# Golden spiral with fibonacci rectangles | |
## Build the spiral | |
def spiral(th): | |
a = 1.120529 | |
b = 0.306349 | |
r = a*exp(-b*th) | |
return (r*cos(th), r*sin(th)) | |
nspiral = 2 # number of spiral loops | |
th = linspace(-pi/13,2*pi*nspiral,1000); # angle | |
(x,y) = spiral(th) | |
yshift = (1.6 - (max(y)-min(y)))/2 # shift the spiral north so that it is centered | |
s = {'x': -x+x[0], 'y': y-y[0]+yshift, 'line':{'color':'white','thickness':3}} # spiral | |
## Build the rectangles as a heatmap | |
# specify the edges of the heatmap squares | |
phi = ( 1+sqrt(5) )/2. | |
xe = [0, 1, 1+(1/(phi**4)), 1+(1/(phi**3)), phi] | |
ye = [0, 1/(phi**3),1/phi**3+1/phi**4,1/(phi**2),1] | |
z = [ [13,3,3,5], | |
[13,2,1,5], | |
[13,10,11,12], | |
[13,8,8,8] | |
] | |
hm = {'x':sort(xe), 'y':sort(ye)+yshift, 'z': z, 'type':'heatmap', | |
'scl':[[0,"rgb(12,51,131)"],[0.25,"rgb(10,136,186)"],[0.5,"rgb(242,211,56)"],[0.75,"rgb(242,143,56)"],[1,"rgb(217,30,30)"]]} | |
layout = {'margin':{'t':200,'r':200,'b':200,'l':200}, | |
'xaxis':{'range':[0,1.6],'autorange':False,'showgrid':False,'zeroline':False,'linecolor':'rgba(0,0,0,0)','showticklabels':False,'ticks':None}, | |
'yaxis':{'range':[0,1.6],'autorange':False,'showgrid':False,'zeroline':False,'linecolor':'rgba(0,0,0,0)','showticklabels':False,'ticks':None}, | |
'showlegend':False,'width':700,'height':700,'autosize':False} | |
plot([s, hm],layout=layout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment