gpt4 book ai didi

python-3.x - 具有 Bokeh 的 Holoview 不显示绘图

转载 作者:行者123 更新时间:2023-12-03 15:50:25 25 4
gpt4 key购买 nike

我正在尝试创建一个环境,在其中我使用 PyCharm 开发 Python 代码,同时使用全息 View 和 Bokeh 创建交互式图表。

我按照 Holoview Introduction 中的步骤操作它在 Jupyter notebook 中工作——图表确实很好地互动。但是,当我在 PyCharm 的 Python 控制台中运行相同的代码时,没有显示图表或浏览器。

相反,当我直接调用 bokeh 的方法时,如 this example ,浏览器启动,我可以交互地操作图表。我想使用 holoviews (+bokeh) 来实现这一点。

非常感谢您提前提供的帮助。

我的图书馆:

  • Python 3.4.5
  • 全息 View 1.8.1
  • Bokeh 0.12.6
  • 参数 1.5.1
  • ipython 6.1.0
  • jupyter 1.0.0
  • Pandas 0.20.3
  • numpy 1.13.1
  • scipy 0.19.1
  • 最佳答案

    唯一需要添加的东西你的代码是show(hv.render(your_holoviews_plot)) , 像这样:

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

    show(hv.render(your_holoviews_plot))

    当您在 PyCharm(或任何其他 IDE)中运行脚本时,这将在浏览器中打开您的绘图。

    它设置 Bokeh 作为渲染器 使用 bokeh.plotting.show() 打开绘图 在浏览器中。
    所以不需要去命令行等。

    完整的工作示例代码:
    # 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))

    关于python-3.x - 具有 Bokeh 的 Holoview 不显示绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45308714/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com