简体   繁体   English

带有散景的 Holoview 不显示图

[英]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.我正在尝试创建一个环境,在其中我使用 PyCharm 开发 Python 代码,同时使用全息视图和散景创建交互式图表。

I followed steps in Holoview Introduction and it works in Jupyter notebook - the charts are nicely interactive indeed.我按照Holoview Introduction 中的步骤 操作,它在 Jupyter notebook 中工作 - 图表确实具有很好的交互性。 However, when I run the same code in PyCharm's Python Console, no charts or browser shows up.但是,当我在 PyCharm 的 Python 控制台中运行相同的代码时,没有显示图表或浏览器。

In contrast, when I directly call bokeh's methods, as in this example , a browser launches and I can manipulate the charts interactively.相比之下,当我直接调用 bokeh 的方法时,如本例所示,浏览器会启动,我可以交互地操作图表。 I would like to achieve this using holoviews (+bokeh).我想使用全息视图(+bokeh)来实现这一点。

Many thanks for your help in advance.非常感谢您的帮助。

My libraries:我的图书馆:

  • Python 3.4.5蟒蛇 3.4.5
  • holoviews 1.8.1全息视图 1.8.1
  • bokeh 0.12.6散景 0.12.6
  • param 1.5.1参数 1.5.1
  • ipython 6.1.0蟒蛇 6.1.0
  • jupyter 1.0.0 jupyter 1.0.0
  • pandas 0.20.3熊猫 0.20.3
  • numpy 1.13.1麻木 1.13.1
  • scipy 0.19.1 scipy 0.19.1

The only thing you need to add to your code is show(hv.render(your_holoviews_plot)) , like this:您唯一需要添加到代码中的是show(hv.render(your_holoviews_plot)) ,如下所示:

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.当您在 PyCharm(或任何其他 IDE)中运行您的脚本时,这将在浏览器中打开您的绘图。

It sets bokeh as renderer and uses bokeh.plotting.show() to open the plot in the browser.它将散景设置为渲染器使用 bokeh.plotting.show()在浏览器中打开绘图
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))

The solution is in: http://holoviews.org/user_guide/Deploying_Bokeh_Apps.html解决方案在: 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然后转到您的命令提示符, cd 到正确的目录并运行: bokeh serve --show myscript.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM