Joy
Joy

Reputation: 769

Altair charts in juypter notebook does not render

I can't figure out what's up in my jupyter notebook. Vincent and Bokeh work fine, but in trying out Altair, I must be missing something, but I'm not erroring and the online docs don't mention my problem.

This is what I enter (from documentation page 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',
)

The code executes in my Jupyter notebook with no errors, but also no graph. I do have vega installed, so that's not the issue. It's not specific to this graph, other examples have the same behavior. I'm not sure how to even troubleshoot this!

Upvotes: 2

Views: 2214

Answers (1)

Pierre Cordier
Pierre Cordier

Reputation: 504

This solved my problem : Display plots in jupyter

Which points to : How to install properly altair in anaconda and enable ipyvega

Install altair :

conda install altair --channel conda-forge

Run this line in command line before launching jupyter :

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

Launch notebook :

jupyter notebook

It displays !

Upvotes: 3

Related Questions