【问题标题】:Altair charts in juypter notebook does not renderjupyter notebook 中的 Altair 图表不呈现
【发布时间】:2017-03-04 19:42:47
【问题描述】:

我无法弄清楚我的 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,所以这不是问题。它不是特定于该图,其他示例具有相同的行为。我什至不知道如何解决这个问题!

【问题讨论】:

标签: python-2.7 jupyter vega


【解决方案1】:

这解决了我的问题:Display plots in jupyter

指向:How to install properly altair in anaconda and enable ipyvega

安装altair:

conda install altair --channel conda-forge

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

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

启动notebook:

jupyter notebook

【讨论】:

  • 嗯...这对我来说不适用于 OSX 和 Anaconda... 命令jupyter nbextension enable vega --py --sys-prefix 导致错误[EnableNBExtensionApp] CRITICAL | Bad config encountered during initialization: [EnableNBExtensionApp] CRITICAL | Unrecognized flag: '--py'。命令conda install altair --channel conda-forge 导致错误Error: Error: post-link failed for: conda-forge::vega-0.4.4-py27_0。可能适用于其他人,但不适用于我的环境。
猜你喜欢
  • 2021-02-06
  • 2016-12-22
  • 2017-03-10
  • 1970-01-01
  • 2018-05-31
  • 1970-01-01
  • 2018-10-14
  • 2019-01-31
  • 2020-06-27
相关资源
最近更新 更多