Two-line streams using bokeh

I would like to create a visualization in which there are two line graphs that are updated with one new point per graph per second. The result will be something like this .

I recently read about bokeh and found out that it can be used to visualize data streams in real time. However, I do not know how to encode in it yet.

I would be grateful if someone would show me how this task can be accomplished using bokeh. thanks!

+5
source share
2 answers

For bokeh-0.11.1 :

Basically, you need to run a python application on a bokeh server. Then everyone can connect to the server and view the graph in real time.

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 start the server from the command line using your program:

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

This will open a browser with your real time chart.

See the bokeh documentation for details.

+11
source

You can add scrolling to your schedule by adding the following to the schedule value in your ad:

 p = figure(plot_width=400, plot_height=400) p.x_range.follow="end" p.x_range.follow_interval = 20 p.x_range.range_padding=0 

where follow_interval = the number of points that accumulate on the chart before scrolling. I believe that you can set the visible range on the chart. FYI I got the scroll code from the OHLC example on the gitHub bokeh page found here: https://github.com/bokeh/bokeh/tree/master/examples/app OHLC is an example of streaming data using the technique "... = new_data" referred to in Bigreddot.

+4
source

All Articles