'm trying to use Bokeh to stream points generated by an algorithm using this class:
class FigurePlot:
def __init__(self):
self.source = ColumnDataSource({'x': [], 'y': []})
self.points = []
def make_document(self, doc):
""" Creates an empty document """
fig = Figure(sizing_mode='scale_width')
fig.circle(source=self.source, x='x', y='y', size=10)
doc.add_periodic_callback(self.stream_points, 150)
doc.add_root(column(fig))
def interactive_plot(self):
"Initialize the server instance """
app = {'/': Application(FunctionHandler(self.make_document))}
server = Server(app, port=5001)
server.show('/')
server.run_until_shutdown()
def stream_points(self):
new = {'x': [p[0] for p in self.points], 'y': [p[1] for p in self.points]}
self.source.stream(new, rollover=len(self.points))
def replace_points(self, points):
""" Update points? """
self.points = points
I call it from an auxiliar class:
class External:
def __init__(self):
self.fig = FigurePlot()
self.fig.interactive_plot()
def update(self, points):
self.fig.replace_points(points)
So after each iteration, the method update()
is called with a new list of points. The problem is that the figure is displayed empty, and I think that the server might be blocking the class. I want to be able to update the plot asynchronously as new points arrives using FigurePlot().
Any help? Thank you in advance!