Timeseries streaming in bokeh

走远了吗. 提交于 2019-12-03 09:48:43

问题


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.


回答1:


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

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.

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

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)

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



来源:https://stackoverflow.com/questions/24800071/timeseries-streaming-in-bokeh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!