Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeseries streaming in bokeh

Tags:

python

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.

like image 732
Maxi Avatar asked Jul 17 '14 09:07

Maxi


1 Answers

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.

like image 154
bigreddot Avatar answered Oct 18 '22 23:10

bigreddot