gpt4 book ai didi

python - 从终端运行脚本时 Altair 不显示图表?

转载 作者:行者123 更新时间:2023-12-04 17:18:49 28 4
gpt4 key购买 nike

我在我的 Mac Pro Big Sur 上学习这个教程示例。

https://altair-viz.github.io/gallery/simple_bar_chart.html

vtest.py如下:

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'
)

当我在终端上执行它时,它没有显示任何内容,没有可视化显示,也没有错误或警告消息。

% python vtest.py

Altair 不能在 Mac OS 上运行吗?

最佳答案

如果您想通过从终端运行脚本来显示 Altair 绘图,您可以使用 .show() 方法在默认浏览器中打开它:

alt.Chart(source).mark_bar().encode(
x='a',
y='b'
).show()

文档包含一个带有 more details about how Altair charts are rendered and how to display them conveniently 的部分, 从这段话开始:

Altair produces Vega-Lite visualizations, which require a Javascript frontend to display the charts. Because notebook environments combine a Python backend with a Javascript frontend, many users find them convenient for using Altair.

关于python - 从终端运行脚本时 Altair 不显示图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67442911/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com