jupyter-notebook - 如何在 Jupyter Notebook 中动态更新 Holoviews 绘图布局?
问题描述
我想通过一个情节的项目在 Jupyter Notebook 中工作。用新数据或新布局更新它,也许在它附近添加/删除其他绘图等等……在 Bokeh 中,我可以使用类似于:
target = show(layout, notebook_handle=True)
push_notebook(handle=target)
在 Holoviews 中,我发现了如何将新数据提供给现有绘图:
pipe = Pipe(data=[])
Image = hv.DynamicMap(hv.Image, streams=[pipe1])
pipe.send(np.random.rand(3,2)) #data change
但是有任何解决方案来管理 Holoviews 中的实时布局更新吗?是否可以通过 .opts() 构造更新现有图?在这个例子中,我将得到一个新的情节:
pipe = Pipe(data=[])
Image = hv.DynamicMap(hv.Image, streams=[pipe])
Image.opts(width=1000,height=1000)
#######new cell in jupyter notebook############
Image.opts(width=100,height=100)
解决方案
这是我对我的问题的一个绝妙答案:
import param
import panel as pn
import numpy as np
import holoviews as hv
from holoviews.streams import Pipe
pn.extension()
pipe = Pipe(data=[])
class Layout(param.Parameterized):
colormap = param.ObjectSelector(default='viridis', objects=['viridis', 'fire'])
width = param.Integer(default=500)
update_data = param.Action(lambda x: x.param.trigger('update_data'), label='Update data!')
@param.depends("update_data", watch=True)
def _update_data(self):
pipe.send(np.random.rand(3,2))
layout = Layout()
Image = hv.DynamicMap(hv.Image, streams=[pipe]).apply.opts(cmap=layout.param.colormap, width=layout.width)
pdmap = pn.panel(Image)
playout = pn.panel(layout)
def update_width(*events):
for event in events:
if event.what == "value":
pdmap.width = event.new
layout.param.watch(update_width, parameter_names=['width'], onlychanged=False)
pn.Row(playout, pdmap)
https://discourse.holoviz.org/t/how-to-update-holoviews-plots-width-height/1947
推荐阅读
- xml - 使用 XSLT 的多行
- angular - Angular:如果为 0,则检查数组长度
- javascript - 如何根据搜索关键字对字符串数组进行排序?
- ruby-on-rails - Rails ActiveStorage:链接到云端
- coq - 在 Coq 中正确地进行双重归纳
- memory - 在打开的项目窗口之间共享 Intellij IDEA 的 ls -Xmx 内存限制?
- selenium - selenium.common.exceptions.WebDriverException:消息:进程意外关闭,状态为 1
- c++ - 在 C++ 中构造字符串
- java - 如何从向量中正确添加和删除对象
- php - 使用 Codeigniter 从 Thunderbird 导入所有联系人详细信息?