6

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.

Yingbo Miao
  • 882
  • 9
  • 12
  • I have the same problem. I try to use pyviz, which require hvplot and holoviews, but didn't work. Pyviz will be really great. https://towardsdatascience.com/pyviz-simplifying-the-data-visualisation-process-in-python-1b6d2cb728f1 – korakot Feb 21 '19 at 01:50
  • Colaboratory has a relatively narrow set of supported libraries, so I'm not surprised it didn't work. I'd recommend sending feedback asking for PyViz support using the menu option in Colaboratory; if enough people ask maybe they will add it! – James A. Bednar Feb 21 '19 at 02:44
  • Hi @JamesA.Bednar, what do you mean "using the menu option" in Colaboratory? – Yingbo Miao Feb 21 '19 at 19:14
  • In Colaboratory, under the "Help" menu, there is an option "Send feedback". – James A. Bednar Feb 22 '19 at 13:18

3 Answers3

12

Call this once

%env HV_DOC_HTML=true

Then, in every cell.

hv.extension('bokeh')

Adapted from this answer by @james-a-bednar

korakot
  • 37,818
  • 16
  • 123
  • 144
5

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)
  • Can you make it works with bokeh as well? If so, I will accept. – korakot Feb 23 '19 at 13:52
  • Check the updated notebook, it has an example with bokeh now, also check the docs for each backend extension you'd use here you will find more about it https://colab.research.google.com/notebooks/charts.ipynb#scrollTo=nv8P3UYm6SiQ – Y. Pablo Camacho Feb 23 '19 at 19:02
  • 2
    You show how to use bokeh. But it doesn't use holoviews at all. Can you plot postage, using hv.Curve? – korakot Feb 24 '19 at 07:53
1

this total worked for me - Call this once

%env HV_DOC_HTML=true Then, in every cell.

hv.extension('bokeh')

below was not plotting before and now it plots in Google colab!

hvplot.extension('bokeh')
# Create a visual aggregation explore the housing units by year
housing_units_by_year.hvplot.bar(
    x="year",
    y="housing_units",
    title='Housing Units in San Francisco from 2010 to 2016',
    color="blue",
    xlabel='Year',
    ylabel="Housing Units"
).opts(yformatter='%.0f')