Skip to content Skip to sidebar Skip to footer

How Do I Get My Interactive Holoviews Graph To Display In Visual Studio (without Jupyter)?

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 Inte

Solution 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 importsimport 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()

Solution 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 showshow(hv.render(your_holoviews_plot))

Full working example:

# import librariesimport 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 browserfrom 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))

Post a Comment for "How Do I Get My Interactive Holoviews Graph To Display In Visual Studio (without Jupyter)?"