Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the Holoviews show graph on Google Colaboratory notebook?

I tried all three backends but didn't show any graph. An example is:

!pip install -q holoviews

import holoviews as hv
from holoviews import opts

hv.extension('matplotlib')


# build a dataset where multiple columns measure the same thing
stamp    = [.33, .33, .34, .37, .37, .37, .37, .39, .41, .42,
            .44, .44, .44, .45, .46, .49, .49]
postcard = [.20, .20, .21, .23, .23, .23, .23, .24, .26, .27,
            .28, .28, .29, .32, .33, .34, .35]

group = "U.S. Postage Rates (1999-2015)"
stamp    = hv.Curve(stamp, vdims='Rate per ounce', label='stamp', group=group)
postcard = hv.Curve(postcard, vdims='Rate per ounce', label='postcard', group=group)
postage = (stamp * postcard)

postage.opts(
    opts.Curve(interpolation='steps-mid', linestyle=hv.Cycle(values=['--', '-'])),
    opts.Overlay(legend_position='top_left'))

The code can run but won't draw any graph in the result.

like image 760
Yingbo Miao Avatar asked Dec 17 '22 18:12

Yingbo Miao


2 Answers

Call this once

%env HV_DOC_HTML=true

Then, in every cell.

hv.extension('bokeh')

Adapted from this answer by @james-a-bednar

like image 112
korakot Avatar answered Dec 26 '22 19:12

korakot


You need to use the matplotlib renderer outside of a Jupyter notebook, this is done as follows: mr = hv.renderer('matplotlib') mr.show(curve)

Working version: https://colab.research.google.com/drive/1CrfBZsTzYjf3NpwQJ1VwjQ_Eq1cjMBpe

!pip install -q holoviews 
import holoviews as hv
from holoviews import opts

hv.extension('matplotlib')


# build a dataset where multiple columns measure the same thing
stamp    = [.33, .33, .34, .37, .37, .37, .37, .39, .41, .42,
            .44, .44, .44, .45, .46, .49, .49]
postcard = [.20, .20, .21, .23, .23, .23, .23, .24, .26, .27,
            .28, .28, .29, .32, .33, .34, .35]

group = "U.S. Postage Rates (1999-2015)"
stamp    = hv.Curve(stamp, vdims='Rate per ounce', label='stamp', group=group)
postcard = hv.Curve(postcard, vdims='Rate per ounce', label='postcard', group=group)
postage = (stamp * postcard)

postage.opts(
    opts.Curve(interpolation='steps-mid', linestyle=hv.Cycle(values=['--', '-'])),
    opts.Overlay(legend_position='top_left'))

mr = hv.renderer('matplotlib')
mr.show(postage)

Bokeh:

import numpy as np
from bokeh.plotting import figure, show
from bokeh.io import output_notebook
hv.extension('bokeh')

output_notebook()
plot = figure(y_axis_label=("U.S. Postage Rates (1999-2015)"), plot_width=300, plot_height=300)
plot.step(x=list(range(0, 17)), y=[.20, .20, .21, .23, .23, .23, .23, .24, .26, .27,
            .28, .28, .29, .32, .33, .34, .35], color="#FB8072")
show(plot)
like image 35
Yumed Pablo Camacho Avatar answered Dec 26 '22 20:12

Yumed Pablo Camacho