Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Bokeh-如何使用定期回调更新ColumnDataSource以绘制流线图_Python_Data Visualization_Bokeh - Fatal编程技术网

Python Bokeh-如何使用定期回调更新ColumnDataSource以绘制流线图

Python Bokeh-如何使用定期回调更新ColumnDataSource以绘制流线图,python,data-visualization,bokeh,Python,Data Visualization,Bokeh,我是Bokeh的新手,希望制作流式线图,但我不知道如何实现Bokeh定期回调。我使用update函数检查了ColumnDataSource更新的给定示例([1]和[2]),但我无法理解 我想从数据库中获取数据并绘图(每次都是新数据)。你能给我举个简单的例子吗?或者指导我如何在代码中实现它 import sqlite3 import time import datetime import time, threading from dateutil import parser from bokeh

我是Bokeh的新手,希望制作流式线图,但我不知道如何实现Bokeh定期回调。我使用update函数检查了ColumnDataSource更新的给定示例([1]和[2]),但我无法理解

我想从数据库中获取数据并绘图(每次都是新数据)。你能给我举个简单的例子吗?或者指导我如何在代码中实现它

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))
谢谢,

问候,

[1]

[2]


问题已解决:注释中给出了解决方案。

您是否尝试添加定期回调(回调,周期为毫秒)。看:是的,我试过了,但没能成功。我还检查了OHLC示例,但我无法确切理解如何更新ColumnDataSource。如果我在一个简单的例子中理解了它,我可以尝试在我的代码中实现它@PabloReyesHi Pablo,它现在可以用了。我在OHLC示例和定期回调中使用了ColumnDataSource,但我更新了“滑块”示例()中给出的数据。它更新所有数据,而不是附加OHLC中给出的数据。我希望这能帮助其他人,所以我想与大家分享@PabloreYes您是否尝试添加定期回调(回调,周期为毫秒)。看:是的,我试过了,但没能成功。我还检查了OHLC示例,但我无法确切理解如何更新ColumnDataSource。如果我在一个简单的例子中理解了它,我可以尝试在我的代码中实现它@PabloReyesHi Pablo,它现在可以用了。我在OHLC示例和定期回调中使用了ColumnDataSource,但我更新了“滑块”示例()中给出的数据。它更新所有数据,而不是附加OHLC中给出的数据。我希望这能帮助其他人,所以我想与大家分享@帕布罗雷耶斯