首页 > 解决方案 > 让 Altair 与 Jupyter Notebook 一起工作

问题描述

试图让 Altair 与 Jupyter Notebook 一起使用,我使用它安装了它

conda install -c conda-forge altair vega_datasets notebook vega

但是当我尝试做一个示例图时

import altair as alt
from vega_datasets import data

# for the notebook only (not for JupyterLab) run this command once per session
alt.renderers.enable('notebook')

iris = data.iris()

alt.Chart(iris).mark_point().encode(
    x='petalLength',
    y='petalWidth',
    color='species'
)

正如他们的快速入门指南中所见,我得到

ValueError: 
To use the 'notebook' renderer, you must install the vega package
and the associated Jupyter extension.
See https://altair-viz.github.io/getting_started/installation.html
for more information.

即使我已经使用 Conda 安装了 vega。不过,我可以制作 vega 示例图。不过,我无法启用 Jupyter 扩展,因为 Jupyter 说它不兼容。

任何帮助表示赞赏。

标签: jupyter-notebookvegaaltair

解决方案


对于当前版本的 altair(2.2 版),请使用

conda install -c conda-forge vega=1.3

或者

pip install vega==1.3

然后重启笔记本。

python 扩展本周被错误地更新为仅支持 vega-lite 3.0,该vega版本尚未发布,因此 Altair 尚不支持。

有关初始错误报告,请参阅https://github.com/altair-viz/altair/issues/1114


推荐阅读