I am trying to add lines to a blank plot on-the-fly. I am planning on creating these lines once in a periodic callback as worker hosts come online. However, when I do this, the lines continue to flicker almost like the lines are being replotted continuously. I have prototyped this behavior in the following minimal example which is also attached. Please let me know of a way to be able to add lines to a plot on-the-fly without knowing them all upfront.
Thanks!
main.py (941 Bytes)
···
“”“Main module for memory app.
“””
import bokeh.io
import bokeh.layouts
import bokeh.models
import bokeh.plotting
DOC = bokeh.io.curdoc()
def memory_plot():
"""Creates the memory plot.
"""
plot = bokeh.plotting.figure()
plot.xaxis.axis_label = "Time"
plot.yaxis.axis_label = "Memory [MiB]"
return plot
PLOT = memory_plot()
LAYOUT = bokeh.layouts.row([PLOT])
SOURCES = {}
def memory_update():
"""Streams data to memory plot.
"""
for i in range(5):
if str(i) not in SOURCES:
print("Creating line", i)
source = bokeh.models.ColumnDataSource(
data={'time': [], 'memory': []})
PLOT.line('time', 'memory', source=source)
data = {'time': [0.0, 1.0], 'memory': [0.0, 2.0*(i+1.0)]}
source.stream(data, 50)
SOURCES[str(i)] = source
DOC.add_periodic_callback(memory_update, 500)
DOC.add_root(LAYOUT)

