简体   繁体   中英

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?

在此处输入图片说明

Try moving the enable line to just after importing altair, eg

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM