问题
I'm mainly using Jupyter Notebook / Lab when using Holoviews for interactive plotting.
How do I make Visual Studio display my interactive graphs and panels, without using the Interactive Jupyter inside Visual Studio?
回答1:
One way to use interactive graphs from Holoviews etc in Visual Studio is executing code to show the graph in your browser (which Holoviews is meant for).
The example below puts your Holoviews graph in a Panel and starts a Bokeh server.
It opens a new tab on your browser and shows your graph.
# 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()
回答2:
Easiest solution is to set bokeh as backend of the renderer and then use bokeh.render.show(). This will open your holoviews plot in the browser:
hv.extension('bokeh')
from bokeh.plotting import show
show(hv.render(your_holoviews_plot))
Full working example:
# import libraries
import numpy as np
import pandas as pd
import hvplot.pandas
import holoviews as hv
# setting bokeh as backend
hv.extension('bokeh')
# going to use show() to open plot in browser
from bokeh.plotting import show
# create some sample data
data = np.random.normal(size=[50, 2])
df = pd.DataFrame(
data=data,
columns=['col1', 'col2'],
)
# using hvplot here to create a holoviews plot
# could have also just used holoviews itself
plot = df.hvplot(kind='scatter', x='col1', y='col2')
# use show() from bokeh
show(hv.render(plot))
来源:https://stackoverflow.com/questions/57971107/how-do-i-get-my-interactive-holoviews-graph-to-display-in-visual-studio-without