Altair charts do not render in notebook

I've taken advantage of the new feature that allows the installing of libraries from pip to try to use the Mode Notebook for Altair charts. Unfortunately, the charts do not seem to render even if all the needed libraries are there.

 

Specifically, here is what I did:

! pip install -U altair vega vega_datasets jupyterlab -t "/tmp" > /dev/null 2>&1
import altair as alt
alt.__version__
# 3.0.0
from vega_datasets import data
alt.renderers.enable("notebook")
print(alt.renderers.active)
# notebook
iris = data.iris()
alt.Chart(iris).mark_point().encode(
    x='petalLength',
    y='petalWidth',
    color='species'
)
# no rendered output

Can someone from the Mode team please chime in?

Thanks

Roberto

2replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Roberto Medri FYI I tried to do this as well but the Mode team told me visualisation libraries through pip are not supported at the moment.

    Like
  • I can confirm that Altair charts do display in Mode with the latest Altair version 4.0.0, you should use the default renderer, don't change it to the "notebook" renderer , see https://github.com/altair-viz/altair/issues/1114#issuecomment-565452072

    I note that an old version of altair ~2 appeared to already be installed, so it is important to run pip with upgrade switch ( as you did, but that tripped me up).
     

    ! pip install --upgrade altair==4.0.0 vega_datasets -t "/tmp" > /dev/null 2>&1

     

    import altair as alt
    import pandas as pd

     

    source = pd.DataFrame({
        'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
        'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
    })
    
    alt.Chart(source).mark_bar().encode(
        x='a',
        y='b'
    )
    Like
Like Follow
  • 4 mths agoLast active
  • 2Replies
  • 105Views
  • 3 Following