简体   繁体   中英

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. Ie 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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM