-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.py
98 lines (85 loc) · 2.64 KB
/
simple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import uuid
import time
from datetime import datetime
fts = datetime.fromtimestamp
from webbrowser import open_new_tab
from random import randint
from collections import OrderedDict
from requests.exceptions import ConnectionError
from bokeh.document import Document
from bokeh.session import Session
from bokeh.widgetobjects import *
from bokeh.objects import DataRange1d, ColumnDataSource, Plot, LinearAxis, Glyph, Grid, DatetimeAxis, HoverTool
from bokeh.glyphs import Quad
document = Document()
session = Session(load_from_config=False)
docname = str(uuid.uuid4())
session.use_doc(docname)
session.load_document(document)
data = {
'l': range(0,1000),
'r': [i+0.1 for i in range(0,1000)],
'b': [0]*1000,
'y': [randint(0,1000) for i in range(1000)]
}
cols = ['l', 'r', 'b', 'y']
source = ColumnDataSource(
data=data,
column_names=cols
)
def update_data():
source.data = data
session.store_document(document)
def _plot():
xdr = DataRange1d(sources=[source.columns(c) for c in ['l','r']])
ydr = DataRange1d(sources=[source.columns('y')])
plot = Plot(data_sources=[source],
x_range=xdr,
y_range=ydr,
title=None,
plot_width=800,
plot_height=500)
quad = Quad(left='l',
right='r',
bottom='b',
top='y',
fill_color='red')
quad_renderer = Glyph(data_source=source,
xdata_range=xdr,
ydata_range=ydr,
glyph=quad)
plot.renderers.append(quad_renderer)
xaxis = DatetimeAxis(plot=plot,
location='bottom',
dimension=0)
xgrid = Grid(plot=plot,
dimension=0,
axis=xaxis)
yaxis = LinearAxis(plot=plot,
location='left',
dimension=1)
ygrid = Grid(plot=plot,
dimension=1,
axis=yaxis)
hover = HoverTool(plot=plot,
tooltips=OrderedDict([
("", "@l")
]),
always_active=True)
plot.tools.append(hover)
return plot
def layout():
return _plot()
document.add(layout())
update_data()
if __name__ == "__main__":
link = session.object_link(document._plotcontext)
open_new_tab(link)
try:
while True:
session.load_document(document)
time.sleep(0.5)
except KeyboardInterrupt:
print()
except ConnectionError:
print("Connection to bokeh-server was terminated")