Getting Altair to work with Jupyter Notebook

戏子无情 提交于 2020-04-10 04:22:08

问题


Trying to get Altair to work with Jupyter Notebook, I installed it using

conda install -c conda-forge altair vega_datasets notebook vega

But when I try to do an example plot

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'
)

as seen in their quick start guide, I get

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.

even though I have installed vega using Conda. I can make vega example plots though. I am unable to enable the Jupyter extension though, as Jupyter says it is incompatible.

Any help is appreciated.


回答1:


For the current release of altair (Version 2.2), use

conda install -c conda-forge vega=1.3

or

pip install vega==1.3

and then restart the notebook.

The vega python extension was mistakenly updated this week to only support vega-lite 3.0, which is not yet released and thus not yet supported by Altair.

See https://github.com/altair-viz/altair/issues/1114 for the initial bug report.



来源:https://stackoverflow.com/questions/52022136/getting-altair-to-work-with-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!