Bokeh-Server: Random data dengan x axis datetime

From OnnoWiki
Revision as of 14:30, 21 February 2016 by Onnowpurbo (talk | contribs)
Jump to navigation Jump to search

Buat randomaja.py

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)


Jalankan Server

bokeh serve --address=192.168.0.100 --host 192.168.0.100:5006 randomaja.py

Browse ke

http://192.168.0.100:5006/randomaja/