http://qiita.com/7of9/items/01848f80188bf5c876d7
の続き
plotlyプロット部分を関数化した。
160103-listPlot.py
import plotly.plotly as py
import time
import datetime
def plotly_plot(xlist, ylist, addnum, grpTtl, filnam):
if len(xlist) < addnum:
return False
py.plot({
"data":[{ "x":xlist, "y":ylist }],
"layout":{ "title": grpTtl }
},filename=filnam
,fileopt='extend'
,privacy='public')
return True
xlist = [0] * 0
ylist = [0] * 0
graphTitle = "graph as a function of time"
filename = "timegraph160103c"
while True:
today = datetime.datetime.today()
xdt = today.strftime("%Y-%m-%d %H:%M:%S")
yval = 3.1415
xlist.append(xdt)
ylist.append(yval)
time.sleep(3)
res = plotly_plot(xlist, ylist, 5, graphTitle, filename)
if res == False:
continue
print "added at " + str(xlist[1:])
del xlist[1:]
del ylist[1:]