ARF
ARF

Reputation: 7694

Python plotting realtime data

I am looking for a way to plot realtime data line plot or scatter plots from python.

With the plots I want to monitor long-running loops when experimenting with algorithms with scientific computing. I.e. to help me answer the question: Are my results still improving with each iteration or can I cancel the loop?

I am looking for a quick and dirty method. I saw that with Bokeh and Dash one can program dashboards with realtime updates, but an awful lot of boilerplate code seems to be required just to get an updating plot.

Upvotes: 1

Views: 1558

Answers (1)

Tony
Tony

Reputation: 8297

Here is a simple "live streaming" example for Bokeh v1.3.0. You can run it with bokeh serve --show app.py

app.py:

from bokeh.plotting import figure, curdoc
from datetime import datetime
import random

plot = figure(plot_width = 1200, x_axis_type = 'datetime', tools = 'pan,box_select,crosshair,reset,save,wheel_zoom')
line = plot.line(x = 'time', y = 'value', line_color = 'black', source = dict(time = [datetime.now()], value = [random.randint(5, 10)]))

def update(): 
    line.data_source.stream(dict(time = [datetime.now()], value = [random.randint(5, 10)]))

curdoc().add_root(plot)
curdoc().add_periodic_callback(update, 1000)

Upvotes: 2

Related Questions