Files
kabuki/prototypes/stream-bokeh.py
2021-05-19 14:31:09 +02:00

40 lines
544 B
Python

#!/usr/bin/env python
from time import sleep
from random import random
from bokeh.plotting import curdoc, figure
from bokeh.models import ColumnDataSource
data = {
"x": [0, 1, 2, 3, 4],
"y": [6, 7, 2, 3, 5]
}
i = len(data["x"])
source = ColumnDataSource(data=data)
p = figure()
p.line(x="x", y="y", source=source)
def update():
global i
i += 1
new = {
"x": [i],
"y": [random()*10]
}
source.stream(new, rollover=50)
doc = curdoc()
doc.add_periodic_callback(update, 500)
doc.add_root(p)