In [1]:
import plotly
plotly.__version__


Out[1]:
'1.12.9'

In [2]:
import numpy as np
import plotly.plotly as py
import plotly.tools as tls
import plotly.graph_objs as go

In [3]:
stream_ids = tls.get_credentials_file()['stream_ids']
print(stream_ids)


['1yakg7nk9p', 'bawgdw8ui9']

In [18]:
stream_id = stream_ids[0]

stream_1 = go.Stream(
    token=stream_id,
    maxpoints=12*24 #measure every 5 minutes, show full day
)

In [19]:
trace1 = go.Scatter(
    x=[],
    y=[],
    mode='lines+markers',
    stream=stream_1
)

data = go.Data([trace1])

In [30]:
layout = go.Layout(title='mL/sec')

fig = go.Figure(data=data, layout=layout)

py.iplot(fig, filename='Water Flow')


Out[30]:

In [31]:
s = py.Stream(stream_id)

s.open()

In [32]:
import datetime
import time

i = 0
k = 5
y=0
time.sleep(5)

while i<500:
    x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    value = np.random.randn(1)[0]
    if value > 0.2:
        y+=1
    elif value > -0.2:
        y=y
    else:
        y-=1
    
    s.write(dict(x=x,y=y))
    
    time.sleep(1)
    
    i+=1
    
s.close()

In [29]:
s.close()

In [27]:
y = 0
i = 0
while i<10:
    x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    value = np.random.randn(1)[0]
    if value > 0.2:
        y+=1
    elif value > -0.2:
        y=y
    else:
        y-=1
    i+=1
    print(y)


1
2
1
2
1
0
1
0
0
-1

In [ ]: