Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Holoview with bokeh does not show plots

I'm trying to create an environment in which I develop Python code with PyCharm while at the same time creating interactive charts using holoviews and bokeh.

I followed steps in Holoview Introduction and it works in Jupyter notebook - the charts are nicely interactive indeed. However, when I run the same code in PyCharm's Python Console, no charts or browser shows up.

In contrast, when I directly call bokeh's methods, as in this example, a browser launches and I can manipulate the charts interactively. I would like to achieve this using holoviews (+bokeh).

Many thanks for your help in advance.

My libraries:

  • Python 3.4.5
  • holoviews 1.8.1
  • bokeh 0.12.6
  • param 1.5.1
  • ipython 6.1.0
  • jupyter 1.0.0
  • pandas 0.20.3
  • numpy 1.13.1
  • scipy 0.19.1
like image 310
tksmrch Avatar asked Jul 25 '17 16:07

tksmrch


People also ask

How do you use Bokeh plots?

plotting : A high level interface for creating visual glyphs. The dataset used for generating bokeh graphs is collected from Kaggle. To create scatter circle markers, circle() method is used. To create a single line, line() method is used.

Does Bokeh use Matplotlib?

Matplotlib, seaborn, ggplot, and Pandas¶Uses bokeh to display a Matplotlib Figure. You can store a bokeh plot in a standalone HTML file, as a document in a Bokeh plot server, or embedded directly into an IPython Notebook output cell. Parameters: fig (matplotlib.

What is Holoviews Python?

HoloViews is an open-source Python library designed to make data analysis and visualization seamless and simple. With HoloViews, you can usually express what you want to do in very few lines of code, letting you focus on what you are trying to explore and convey, not on the process of plotting.


Video Answer


2 Answers

The only thing you need to add to your code is show(hv.render(your_holoviews_plot)), like this:

import holoviews as hv
hv.extension('bokeh')
from bokeh.plotting import show

show(hv.render(your_holoviews_plot))

When you run your script in PyCharm (or any other IDE), this will open your plot in the browser.

It sets bokeh as renderer and uses bokeh.plotting.show() to open the plot in the browser.
So no need to go to the commandline etc.

Full working example code:

# import libraries
import 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 browser
from 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))
like image 169
Sander van den Oord Avatar answered Sep 25 '22 21:09

Sander van den Oord


The solution is in: http://holoviews.org/user_guide/Deploying_Bokeh_Apps.html

you need these lines of code:

import holoviews.plotting.bokeh
....
layout=#whathever holoview you want to plot
...
doc = hv.renderer('bokeh').server_doc(layout)

And then go to your command prompt, cd to the right directory and run: bokeh serve --show myscript.py

like image 29
Joris Avatar answered Sep 25 '22 21:09

Joris