使用bokeh流化两个折线图 [英] Streaming two line graphs using bokeh

查看:76
本文介绍了使用bokeh流化两个折线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个可视化,其中有两个折线图,每个折线图每秒更新一个新点.

I want to create a visualization where there are two line graphs that are updated with one new point per line graph per second.

我最近阅读了有关bokeh的信息,发现它可以用于实时可视化数据流.但是,我还不知道如何编写代码.

I have recently read about bokeh and found out that it can be used in visualizing streams of data in real-time. However, I don't know how to code in it yet.

如果有人可以向我展示如何使用bokeh完成此任务,我将不胜感激.谢谢!

I would appreciate it if someone can show me how this task can be done using bokeh. Thanks!

推荐答案

对于bokeh-0.11.1:

基本上,您需要在bokeh服务器中运行python应用.然后任何人都可以连接到服务器并实时查看图形.

Basically, you need to run you python app in the bokeh server. Then anyone can connect to the server and view the graph in realtime.

首先,编写您的程序.例如,使用以下代码:

First, write your program. Use this code for example:

# myplot.py
from bokeh.plotting import figure, curdoc
from bokeh.driving import linear
import random

p = figure(plot_width=400, plot_height=400)
r1 = p.line([], [], color="firebrick", line_width=2)
r2 = p.line([], [], color="navy", line_width=2)

ds1 = r1.data_source
ds2 = r2.data_source

@linear()
def update(step):
    ds1.data['x'].append(step)
    ds1.data['y'].append(random.randint(0,100))
    ds2.data['x'].append(step)
    ds2.data['y'].append(random.randint(0,100))  
    ds1.trigger('data', ds1.data, ds1.data)
    ds2.trigger('data', ds2.data, ds2.data)

curdoc().add_root(p)

# Add a periodic callback to be run every 500 milliseconds
curdoc().add_periodic_callback(update, 500)

然后使用您的程序从命令行运行服务器:

Then run the server from the command line, with your program:

C:\>bokeh serve --show myplot.py

这将打开带有实时图形的浏览器.

This will open the browser with your realtime graph.

有关所有详细信息,请参见 bokeh服务器文档.

For all the details see the bokeh server documentation.

这篇关于使用bokeh流化两个折线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆