push_notebook 未更新散景变化 data_source
Bokeh change data_source aren't updated by push_notebook
我无法持续更新显示的图形。有人可以帮帮我吗?
#!/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)
我每次都尝试删除旧字形并添加一个新字形,它确实有效。但是,我不明白为什么这种随处可见的简单用法在这里不起作用。
这里还有笔记本的要点:https://gist.github.com/uduse/f2b17bc67de8fd0ee32f34a87849c8b6
从 vis
创建 line
后尝试创建图的 handle
。
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()
line = vis.line()
line.data_source = to_data_source(np.random.randn(30))
## Handle defined here after adding stuff to the figure
handle = show(vis, notebook_handle=True)
push_notebook(handle=handle)
# this will NOW UPDATE the figure
line.data_source.data['y'] += np.arange(30)
push_notebook(handle=handle)
实际上,我不确定它为什么会这样,但它应该那样工作。
希望对您有所帮助。
这实际上是一个已知错误。参见 https://github.com/bokeh/bokeh/issues/8244
我无法持续更新显示的图形。有人可以帮帮我吗?
#!/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)
我每次都尝试删除旧字形并添加一个新字形,它确实有效。但是,我不明白为什么这种随处可见的简单用法在这里不起作用。
这里还有笔记本的要点:https://gist.github.com/uduse/f2b17bc67de8fd0ee32f34a87849c8b6
从 vis
创建 line
后尝试创建图的 handle
。
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()
line = vis.line()
line.data_source = to_data_source(np.random.randn(30))
## Handle defined here after adding stuff to the figure
handle = show(vis, notebook_handle=True)
push_notebook(handle=handle)
# this will NOW UPDATE the figure
line.data_source.data['y'] += np.arange(30)
push_notebook(handle=handle)
实际上,我不确定它为什么会这样,但它应该那样工作。
希望对您有所帮助。
这实际上是一个已知错误。参见 https://github.com/bokeh/bokeh/issues/8244