我想使用altair查看 Jupyter notebook 中的图表。所以我尝试了教程示例。我已经安装了所需的软件包。这是我的代码:
import altair as alt
from vega_datasets import data
# Uncomment/run this line to enable Altair in the classic notebook
# (this is not necessary in JupyterLab)
alt.renderers.enable('notebook')
cars = data.cars()
chart = alt.Chart(cars).mark_circle().encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
)
chart
我得到的是字典而不是图表。像这样:
Chart({
data: Acceleration Cylinders Displacement Horsepower Miles_per_Gallon \
0 12.0 8 307.0 130.0 18.0
1 11.5 8 350.0 165.0 15.0
2 11.0 8 318.0 150.0 18.0
3 12.0 8 304.0 150.0 16.0
使用此命令安装数据集时:
conda install -c conda-forge altair vega_datasets notebook vega3
这个错误可能是原因还是有其他问题?