first proper prototype
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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()
|
||||
self.fig = row(timeseries.fig, histo.fig)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user