11# Learn about API authentication here: https://plot.ly/python/getting-started
22# Find your api_key here: https://plot.ly/settings/api
33
4- from numpy import *
4+ import numpy as np
55import plotly.plotly as py
66
77# Golden spiral with fibonacci rectangles
88
99## Build the spiral
1010def spiral(th):
1111 a = 1.120529
12- b = 0.306349
13- r = a*exp(-b*th)
14- return (r*cos(th), r*sin(th))
12+ b = 0.306349
13+ r = a*np. exp(-b*th)
14+ return (r*np. cos(th), r*np. sin(th))
1515
1616nspiral = 2 # number of spiral loops
1717
18- th = linspace(-pi/13,2*pi*nspiral,1000); # angle
18+ th = np. linspace(-np. pi/13,2*np. pi*nspiral,1000); # angle
1919(x,y) = spiral(th)
2020
2121# shift the spiral north so that it is centered
22- yshift = (1.6 - (max(y)-min(y)))/2
22+ yshift = (1.6 - (max(y)-min(y)))/2
2323
24- s = dict(x= -x+x[0], y= y-y[0]+yshift,
24+ s = dict(x= -x+x[0], y= y-y[0]+yshift,
2525 line =dict(color='white',width=3)) # spiral
2626
2727# Build the rectangles as a heatmap
2828# specify the edges of the heatmap squares
29- phi = ( 1+sqrt(5) )/2.
30- xe = [0, 1, 1+(1/(phi**4)), 1+(1/(phi**3)), phi]
29+ phi = ( 1+np. sqrt(5) )/2.
30+ xe = [0, 1, 1+(1/(phi**4)), 1+(1/(phi**3)), phi]
3131ye = [0, 1/(phi**3),1/phi**3+1/phi**4,1/(phi**2),1]
3232
3333z = [ [13,3,3,5],
3636 [13,8,8,8]
3737 ]
3838
39- hm = dict(x = sort(xe),
40- y = sort(ye)+yshift,
41- z = z,
42- type = 'heatmap',
39+ hm = dict(x = np. sort(xe),
40+ y = np. sort(ye)+yshift,
41+ z = z,
42+ type = 'heatmap',
4343 colorscale = 'Viridis')
4444
45- axis_template = dict(range = [0,1.6], autorange = False,
46- showgrid = False, zeroline = False,
47- linecolor = 'black', showticklabels = False,
45+ axis_template = dict(range = [0,1.6], autorange = False,
46+ showgrid = False, zeroline = False,
47+ linecolor = 'black', showticklabels = False,
4848 ticks = '' )
4949
5050layout = dict( margin = dict(t=200,r=200,b=200,l=200),
5151 xaxis = axis_template,
5252 yaxis = axis_template,
5353 showlegend = False,
54- width = 700, height = 700,
54+ width = 700, height = 700,
5555 autosize = False )
5656
5757figure = dict(data=[s, hm],layout=layout)
5858
59- url = py.plot(figure, filename='golden spiral', height=750)
59+ url = py.plot(figure, filename='golden spiral', height=750)
0 commit comments