push_notebook不更新散景更改data_source

我在不断更新显示的图形时遇到问题。有人可以帮我吗?

#!/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

以上是push_notebook不更新散景更改data_source的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>