Bokeh: Plot Random Data dengan Axis Datetime

From OnnoWiki
Jump to navigation Jump to search
import sys
import time
import socket
import random
import datetime

from numpy import cumprod, linspace, random
from bokeh.plotting import figure,  output_server, show, cursession, vplot, output_file

TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
output_file("coba5.html")

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(1000):
  n  = datetime.datetime.now()
  x += ['%d.%d'%(n.minute*60+n.second,n.microsecond)]
  y += [random.random()]
  time.sleep(0.01)

p = figure(x_axis_type="datetime",tools=TOOLS)
# p = figure(tools=TOOLS)
p.line(x, y,  name='randomaja',color='#1F78B4',legend='Analog 1')

show(p)