【问题标题】:Bokeh doesn't find Bar-chart modules on Raspberry PiBokeh 在 Raspberry Pi 上找不到条形图模块
【发布时间】:2019-08-21 20:24:54
【问题描述】:

_我正在尝试使用 Bokeh 制作条形图以输出为 .html 文件。简单的绘图一切正常,但由于某种原因,当我尝试运行以下代码时:

from bokeh.charts import Bar, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Bar(df, label='yr', values='mpg', agg='mean',
    title="Average MPG by YR")

output_file("bar.html")_

我最终得到一个错误提示:

ImportError: 没有名为“bokeh.charts”的模块

我已经通过 pip 安装了 Pandas、Numpy,它们都可以使用 help('modules') 命令找到。我知道高级散景图需要 Pandas,它是通过 Pip 安装的

熊猫版本:0.20.3 散景版本:0.12.9 Python 是 3.4.2 版

我也尝试过不同的导入命令,“from bokeh import *”等,但似乎没有任何效果。

【问题讨论】:

    标签: python python-3.x pandas bokeh raspberry-pi3


    【解决方案1】:

    除了Holoviews,如果你只需要简单的条形图,这些现在也很容易从稳定的bokeh.plotting API中制作出来,例如:

    group = df.groupby('cyl')
    source = ColumnDataSource(group)
    
    cyl_cmap = factor_cmap('cyl', palette=Spectral5, factors=sorted(df.cyl.unique()))
    
    p = figure(plot_height=350, x_range=group, title="MPG by # Cylinders")
    
    p.vbar(x='cyl', top='mpg_mean', width=1, source=source,
           line_color=cyl_cmap, fill_color=cyl_cmap)
    

    【讨论】:

    • 谢谢!解决了我的问题,Bokeh 自己的教程仍然指出这个已弃用的版本,他们应该修复它们。
    • 它们都应该更新了,你能指出一些已经过时的具体链接吗?
    【解决方案2】:

    bokeh.charts 一直是deprecated。您可以通过安装和导入 bkcharts 包来恢复该功能,但未来将不支持此功能。 Bokeh 开发人员建议检查 holoviews(它使用 bokeh 作为可能的后端)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-07
      • 1970-01-01
      • 2023-04-09
      • 2022-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多