Bokeh-Server: Random data dengan x axis datetime

From OnnoWiki
Revision as of 09:52, 30 November 2015 by Onnowpurbo (talk | contribs)
Jump to navigation Jump to search
import sys
import time
import socket
import random
import datetime

from bokeh.plotting import figure, output_server, show, cursession
 output_server("randomaja",url='http://192.168.0.100:5006')

x = [0]
y = [0]
i = 0
n  = datetime.datetime.now()
x = ['%d.%d'%(n.minute*60+n.second,n.microsecond)]
y = [random.random()]
for i in xrange(100):
  n  = datetime.datetime.now()
  x += ['%d.%d'%(n.minute*60+n.second,n.microsecond)]
  y += [random.random()]

p = figure(x_axis_type="datetime")
p.line(x, y, name='randomaja')

show(p)

renderer = p.select(dict(name="randomaja"))
ds = renderer[0].data_source 

ds.data["x"] = x
ds.data["y"] = y
cursession().store_objects(ds)
time.sleep(0.1)