I'm having trouble continuously update a shown figure. Could someone help me, please?
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import numpy as np
import bokeh
from bokeh.io import push_notebook, show, output_notebook
from bokeh import layouts
from bokeh.plotting import figure
output_notebook()
# In[2]:
def to_data_source(y):
y = np.array(y)
x = np.arange(y.size)
return bokeh.models.ColumnDataSource({
'x': x,
'y': y
})
# In[3]:
# this will plot an empty figure
vis = figure()
handle = show(vis, notebook_handle=True)
# In[4]:
# this will plot on the empty figure
line = vis.line()
line.data_source = to_data_source(np.random.randn(30))
push_notebook(handle=handle)
# In[5]:
# this will not update the figure
line.data_source.data['y'] += np.arange(30)
push_notebook(handle=handle)
# In[6]:
# this will not update the figure
line.update(data_source=to_data_source(line.data_source.data['y'] + np.arange(30)))
push_notebook(handle=handle)
# In[7]:
# this will plot the correct figure that should've been updated to the previous `show`
show(vis)
I tried removing the old glyph and adding a new one every time, and it actually works. However, I don't understand why this simple usage that I see everywhere doesn't work here.
Also gist of the notebook here: https://gist.github.com/uduse/f2b17bc67de8fd0ee32f34a87849c8b6
from Bokeh change data_source aren't updated by push_notebook
No comments:
Post a Comment