Created
March 25, 2020 18:36
-
-
Save candale/1697231c0f6e3705dcfebc1c748a85c1 to your computer and use it in GitHub Desktop.
Bokeh Real Time Graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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