LoginSignup
0
0

More than 5 years have passed since last update.

RPi / python > plotly > 時系列グラフ > プロットを関数化 > 5個単位でのプロット例

Last updated at Posted at 2016-01-03

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:]

結果 https://plot.ly/276/~7of9/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0