58 lines
1.1 KiB
Python
58 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
|
|
from time import sleep, time
|
|
from random import random
|
|
import numpy as np
|
|
from epics import PV
|
|
from bokeh.plotting import curdoc, figure
|
|
from bokeh.models import ColumnDataSource
|
|
from bokeh.layouts import row
|
|
|
|
|
|
data = {
|
|
"x": [],
|
|
"y": []
|
|
}
|
|
|
|
source = ColumnDataSource(data=data)
|
|
histo = ColumnDataSource(dict(left=[], right=[], top=[]))
|
|
|
|
fig1 = figure()
|
|
fig1.step(x="x", y="y", source=source, mode="after")
|
|
fig1.circle(x="x", y="y", source=source)
|
|
|
|
fig2 = figure()
|
|
fig2.quad(left="left", right="right", top="top", bottom=0, source=histo)
|
|
|
|
pv = PV("MTEST:RAND0")
|
|
|
|
cache = {
|
|
"x": [],
|
|
"y": []
|
|
}
|
|
|
|
def cb(value=None, **kwargs):
|
|
x = time()
|
|
y = value
|
|
cache["x"].append(x)
|
|
cache["y"].append(y)
|
|
|
|
def update():
|
|
source.stream(cache, rollover=50)
|
|
cache["x"] = []
|
|
cache["y"] = []
|
|
data = source.data["y"]
|
|
counts, edges = np.histogram(data, bins="auto")
|
|
histo.data.update(left=edges[:-1], right=edges[1:], top=counts)
|
|
|
|
|
|
|
|
pv.add_callback(cb)
|
|
doc = curdoc()
|
|
doc.add_periodic_callback(update, 1000)
|
|
plt = row(fig1, fig2)
|
|
doc.add_root(plt)
|
|
|
|
|
|
|