散景中的时间流 [英] Timeseries streaming in bokeh

查看:57
本文介绍了散景中的时间流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在bokeh中绘制实时时间序列.我只想在每次更新时绘制新的数据点.我该怎么办?

I want to plot a live time series in bokeh. I want to plot only the new data points at each update. How can I do this ?

背景虚化网站上有一个用于动画情节的示例,但它涉及每次重新绘制整个图片.另外,我正在寻找一个简单的示例,可以逐点实时绘制时间序列.

There is an example on the bokeh website for animated plots but it involves redrawing the whole picture every time. Also I am looking for a simple example where I can do a live plot of a time series point by point.

推荐答案

从Bokeh 0.11.1开始,现在存在到Bokeh服务器应用程序中的列数据源的流接口.您可以在此处查看并轻松运行示例:

As of Bokeh 0.11.1 there is now a streaming interface to column data sources in Bokeh server apps. You can see and easily run an example here:

https://github.com/bokeh/bokeh/tree/master/examples/app/ohlc

该示例显示了带有MACD指标(基于合成刻度数据)的实时更新OHLC图表,该图表仅在每次更新时使用最新数据点来更新图表.

That example shows a live updating OHLC chart with MACD indicator (based on synthetic tick data) that only updates the plot with the most recent data points on every update.

基本上,使用流接口包括两个部分.首先创建一个与列数据源具有相同形状"的新dict:

Basically, using the streaming interface consists of two parts. First create a new dict with same "shape" as your column data source:

new_data = dict(
    time=[t],
    open=[open],
    high=[high],
    low=[low],
    close=[close],
    average=[average],
    color=[color],
)

然后将其传递给.stream方法,并带有一个可选的rollover参数,该参数指定要在浏览器中保留的缓冲区大小(早期的数据开始丢失):

Then pass this to the .stream method, with an optional rollover argument that specifies how big of a buffer to keep in the browser (earlier data starts to get dropped off):

source.stream(new_data, 300)

然后,将仅将new_data中的少量数据发送到绘图,而不是所有数据.

Then, just the small amount of data in new_data willbe sent to the plot, not everything.

这篇关于散景中的时间流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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