2

我无法弄清楚我的 jupyter 笔记本中发生了什么。Vincent 和 Bokeh 工作正常,但在试用 Altair 时,我一定遗漏了一些东西,但我没有出错,在线文档也没有提到我的问题。

这就是我输入的内容(来自文档页面https://altair-viz.github.io/gallery/bar_aggregate.html

from altair import *
Chart('http://vega.github.io/vega-lite/data/population.json',
    description='A bar chart showing the US population distribution of age groups in 2000.',
).mark_bar().encode(
    x=X('sum(people):Q',
        axis=Axis(
            title='population',
        ),
    ),
    y=Y('age:O',
        scale=Scale(
            bandSize=17.0,
        ),
    ),
).transform_data(
    filter='datum.year == 2000',
)

代码在我的 Jupyter 笔记本中执行,没有错误,但也没有图表。我确实安装了 vega,所以这不是问题。它不特定于该图,其他示例具有相同的行为。我不知道如何解决这个问题!

4

1 回答 1

3

这解决了我的问题:在 jupyter 中显示图

这指向:如何altair在anaconda中正确安装并启用ipyvega

安装altair

conda install altair --channel conda-forge

在启动之前在命令行中运行此行jupyter

jupyter nbextension enable vega --py --sys-prefix

发射notebook

jupyter notebook

它显示!

于 2016-10-23T15:40:03.637 回答