我是Bokeh的新手,想制作流线图,但我无法理解如何实现散景定期回调。我使用更新函数检查了给定的示例([1]和[2])以获取ColumnDataSource更新,但我无法理解。
[1] https://github.com/bokeh/bokeh/blob/master/examples/app/spectrogram/main.py
[2] https://github.com/bokeh/bokeh/blob/master/examples/app/ohlc/main.py
我想从数据库和绘图中获取数据(每次新的数据都是peridocially)。你能给我一个非常简单的例子吗?或者指导我如何将其实现到我的代码中。
import sqlite3
import time
import datetime
import time, threading
from dateutil import parser
from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.layouts import column
p = figure(plot_width=800, plot_height=200)
p2 = figure(plot_width=800, plot_height=200)
conn = sqlite3.connect('data.db')
c = conn.cursor()
p_time = datetime.datetime.now() - datetime.timedelta(minutes=15)
c.execute('SELECT Date_Time, Inactive_Time, signal FROM PlotData WHERE Interface=(?) AND Date_Time>(?)',('wlan0',p_time,))
data = c.fetchall()
xs = []
ys = []
zs = []
for row in data:
xs.append(parser.parse(row[0]))
ys.append(row[1])
zs.append(row[2])
p.line(xs, ys, line_width=2)
p2.line(xs, zs, line_width=2)
curdoc().add_root(column(p,p2))
谢谢,
此致