-
-
Save msund/7622558 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
#plot.ly Example | |
# | |
#This example plot | |
#https://plot.ly/~GermanJimenez/0/ | |
import plotly | |
import os | |
def collatzDropTime(n): | |
c = 0 | |
while n != 1: | |
if n % 2 == 0: n /= 2 | |
else: n = ( 3 * n ) + 1 | |
c += 1 | |
return c | |
def average(l): | |
return sum(l)/len(l) | |
limit = 2000 | |
#Collatz algorithm droping times------------------------------------- | |
#Coordinates | |
collatzTrace = { | |
'x': range( 1, limit ), | |
'y': [collatzDropTime( n ) for n in range(1,limit)] | |
} | |
#Styles | |
collatzTraceStyles = { | |
"type":"scatter", | |
"name":"Collatz droping times", | |
"line":{"color":"orange", | |
"width":2, | |
"dash":"solid", | |
"opacity":0.2 | |
} | |
} | |
#Collatz algorithm droping times averages----------------------------------- | |
rang = limit/100 | |
la = [collatzTrace['y'][x:x+rang] for x in range(0, len(collatzTrace['y']), rang)] | |
xs = range(1,limit+2,rang) | |
ys = [average(l) for l in la] | |
ys.append(ys[len(ys)-1]) | |
#Coordinates | |
collatzAverages = { | |
'x': xs, | |
'y': ys, | |
} | |
#Styles | |
collatzAveragesStyles = { | |
"type":"scatter", | |
"name":"Droping times averages (%s)" % rang, | |
"line":{"opacity": 0.3, | |
"color":"gray", | |
"width":3, | |
"dash":"solid" | |
}, | |
} | |
#------------------------------------------------------------------------------- | |
#response = plotly.signup(username, email) #Signup | |
#loggin | |
username = 'MyUserName' | |
email='MyEmail' | |
key = 'MyKey' | |
py = plotly.plotly(username, key) | |
response = py.plot(collatzTrace,collatzAverages) | |
py.style(collatzTraceStyles,collatzAveragesStyles) | |
url = response['url'] | |
filename = response['filename'] | |
if url: | |
#os.system('firefox %s' % url) | |
os.system('explorer %s' % url) | |
#os.system('google-chrome %s' % url) | |
#This example plot | |
#https://plot.ly/~GermanJimenez/0/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment