Hello,
I try to update a figure by adding a new plot by setting the old one’s data source columns to be empty lists via callback.
Without using a legend, everything works. Otherwise the new plots resize weird. What is bokeh’s problem ?
Example:
from bokeh.plotting import figure, curdoc
from bokeh.layouts import column
from bokeh.models import Button, ColumnDataSource
i = 0
plot_sources = []
source = ColumnDataSource(data=dict(x=[1, 2], y=[2, 3]))
plot_sources.append(source)
p = figure(width=400, height=400)
p.circle("x", "y", source=source, legend="text")
def callback():
global i, plot_sources
i += 1
for source in plot_sources:
source.data = dict(x=[], y=[])
source = ColumnDataSource(data=dict(x=[1, 3], y=[i, 5]))
plot_sources.append(source)
p.circle("x", "y", source=source, legend="text %d" % i)
button = Button(label="Press Me")
button.on_click(callback)
curdoc().add_root(column(p, button))
``
starting with:
bokeh serve --show app.py

