Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh inside Google Colab

Matplotlib doesn't give me the visualisation I want

I like the interactive features of Bokeh and I would like to see if someone was able to get it running inside Google Colab?

I installed the library (from the notebook itself) and it showed the installation is successful

!pip install bokeh

but when I use it. It doesn't show anything (not even an error). Just blank output. When I check chrome's Javascript console, I see the follwoing

Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing

like image 793
Abdelwahed Avatar asked Jan 17 '18 06:01

Abdelwahed


2 Answers

There's a Bokeh sample in the charts example notebook.

I suspect the important bit you'll need to add is:

from bokeh.io import output_notebook
output_notebook()

And most importantly output_notebook() must be called inside the same cell

like image 126
Bob Smith Avatar answered Sep 22 '22 07:09

Bob Smith


I made a library to make it easier to use bokeh in Colab

First install it

!pip install kora

Then your can plot a figure easily

from kora.bokeh import figure
p = figure(100, 200)  # h, w
p.line([1, 2, 3, 4], [6, 7, 2, 4])
p # display itself, don't need show()

If you call from kora import bokeh, it can work the same as import bokeh. Or you can use them together as well. What I did is just create _repr_html_() that help display the Figure object.

like image 26
korakot Avatar answered Sep 22 '22 07:09

korakot