首页 > 解决方案 > 如何让我的交互式 Holoviews 图形显示在 Visual Studio(没有 Jupyter)中?

问题描述

在使用 Holoviews 进行交互式绘图时,我主要使用 Jupyter Notebook / Lab。
如何让 Visual Studio 显示我的交互式图形和面板,而不使用 Visual Studio 中的交互式 Jupyter?

标签: pythonvisual-studioholoviewsholovizpanel-pyviz

解决方案


在 Visual Studio 中使用来自 Holoviews 等的交互式图表的一种方法是执行代码以在浏览器中显示图表(Holoviews 就是为此而设计的)。
下面的示例将您的 Holoviews 图形放在面板中并启动 Bokeh 服务器。
它会在您的浏览器上打开一个新选项卡并显示您的图表。

# library imports
import numpy as np
import pandas as pd
import holoviews as hv
hv.extension('bokeh', logo=False)
import panel as pn

# create sample data
data = np.random.normal(size=[50, 2])
df = pd.DataFrame(data, columns=['col1', 'col2'])

# create holoviews graph
hv_plot = hv.Points(df)

# display graph in browser
# a bokeh server is automatically started
bokeh_server = pn.Row(hv_plot).show(port=12345)

# stop the bokeh server (when needed)
bokeh_server.stop()

推荐阅读