Search code examples
python-3.xbokehholoviews

How to view Bokeh/Holoview plots other than in Jupyter Notebook?


I have a simple Holoviews code for a chord diagram that runs and displays the plot in my Jupyter Notebook. It compiles without errors in my shell as well but I can't view the plot anywhere. Is there a function to view the plot in the console itself? Here's the full code

import pandas as pd
import holoviews as hv
from holoviews import opts, dim
from bokeh.sampledata.les_mis import data


hv.extension('bokeh')
hv.output(size = 200)

links = pd.DataFrame(data['links'])
#print(links.head())
hv.Chord(links)

nodes = hv.Dataset(pd.DataFrame(data['nodes']), 'index')
nodes.data.head()


chord = hv.Chord((links, nodes)).select(value=(5, None))
chord.opts(
    opts.Chord(cmap='Category20', edge_cmap='Category20', edge_color=dim('source').str(), 
               labels='name', node_color=dim('index').str()))

Solution

  • We have long been planning to add an explicit show function to HoloViews but never decided on the exact semantics. For now the easiest approach is to simply use the hv.render function to convert the HoloViews object to a bokeh figure and then use bokeh functions to display it, in your case that would look like this:

    from bokeh.plotting import show, output_file
    
    output_file('test.html')
    
    show(hv.render(chord))
    

    This should save a file and open the plot in a new browser window.