Skip to content

Instantly share code, notes, and snippets.

@candale
Created March 25, 2020 18:36
Show Gist options
  • Save candale/1697231c0f6e3705dcfebc1c748a85c1 to your computer and use it in GitHub Desktop.
Save candale/1697231c0f6e3705dcfebc1c748a85c1 to your computer and use it in GitHub Desktop.
Bokeh Real Time Graph
# stolen from https://rehn.me/posts/python-real-time-plotting.html
# in case that disappears
import random
from bokeh.driving import count
from bokeh.models import ColumnDataSource
from bokeh.plotting import curdoc, figure
UPDATE_INTERVAL = 100
ROLLOVER = 100 # Number of displayed data points
source = ColumnDataSource({"x": [], "y": []})
def make_y():
return random.random()
@count()
def update(x):
y = make_y()
source.stream({"x": [x], "y": [y]}, rollover=ROLLOVER)
p = figure()
p.line("x", "y", source=source)
doc = curdoc()
doc.add_root(p)
doc.add_periodic_callback(update, UPDATE_INTERVAL)
'''
Now just run this in the shell
bokeh serve --show plot.py
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment