user14932840
user14932840

Reputation:

Python Altair Vega chart not displaying

I have the following code snippet:

import altair as alt
import pandas as pd

alt.renderers.enable('default')

data = pd.DataFrame({'a': list('CCCDDDEEE'),
                     'b': [2, 7, 4, 1, 2, 6, 8, 4, 7]})

chart = alt.Chart(data)

alt.Chart(data).mark_point().encode(
    x='a',
    y='b'
)

I have installed Altair and Vega and Notebook already:

Altair version: 4.1.0

Notebook version: 6.4.0

Vega version: 3.5.0

Python version: 3.7.8

http://localhost:8889/tree#notebooks is open in a tab.

When I run my Python program, nothing happens.

What am I missing?

enter image description here

Upvotes: 0

Views: 790

Answers (1)

Matt Pitkin
Matt Pitkin

Reputation: 6497

Try moving the enable line to just after importing altair, e.g.

import altair as alt
alt.renderers.enable('default')

then restarting the kernel and re-running. That seems to work for me.

Upvotes: 1

Related Questions