78 lines
1.6 KiB
Python
78 lines
1.6 KiB
Python
import numpy as np
|
|
|
|
from bokeh.plotting import figure
|
|
from bokeh.layouts import row
|
|
from bokeh.models import ColumnDataSource
|
|
|
|
|
|
class Plot0D:
|
|
|
|
def __init__(self):
|
|
self.timeseries = timeseries = TimeSeries()
|
|
self.histo = histo = Histo()
|
|
#TODO: if not set, width and height are None
|
|
width = timeseries.fig.width + histo.fig.width
|
|
height = max(timeseries.fig.height, histo.fig.height)
|
|
self.fig = row(timeseries.fig, histo.fig, width=width, height=height)
|
|
|
|
def set(self, times, values):
|
|
self.timeseries.set(times, values)
|
|
self.histo.set(values)
|
|
|
|
|
|
|
|
class TimeSeries:
|
|
|
|
def __init__(self):
|
|
data = {
|
|
"x": [],
|
|
"y": []
|
|
}
|
|
|
|
self.source = source = ColumnDataSource(data=data)
|
|
|
|
self.fig = fig = figure()
|
|
fig.step(x="x", y="y", source=source, mode="after")
|
|
fig.circle(x="x", y="y", source=source)
|
|
|
|
|
|
def set(self, times, values):
|
|
data = {
|
|
"x": times,
|
|
"y": values
|
|
}
|
|
|
|
self.source.data.update(data)
|
|
|
|
|
|
|
|
class Histo:
|
|
|
|
def __init__(self):
|
|
data = {
|
|
"left": [],
|
|
"right": [],
|
|
"top": []
|
|
}
|
|
|
|
self.source = source = ColumnDataSource(data)
|
|
|
|
self.fig = fig = figure()
|
|
fig.quad(left="left", right="right", top="top", bottom=0, source=source)
|
|
|
|
|
|
def set(self, values):
|
|
data = hist(values)
|
|
self.source.data.update(data)
|
|
|
|
|
|
|
|
def hist(values, bins="auto"):
|
|
counts, edges = np.histogram(values, bins="auto")
|
|
left = edges[:-1]
|
|
right = edges[1:]
|
|
return dict(left=left, right=right, top=counts)
|
|
|
|
|
|
|