我注意到Vega-Lite 3.0.0 发行说明中提到“默认包含工具提示”,这适用于 Altair 3.0 中的箱线图,但不适用于直方图等其他图。
当我在 Vega Editor 中打开我的 Altair 图时,我会看到图表定义顶部"mark": {"tooltip": null}}的config部分。如果我删除"mark": {"tooltip": null},工具提示会自动工作。
所以,而不是这个:
{
"config": {"view": {"width": 400, "height": 300}, "mark": {"tooltip": null}},
"data": {
"url": "https://vega.github.io/vega-datasets/data/seattle-temps.csv"
},
"mark": "bar",
"encoding": {
"x": {"type": "quantitative", "bin": true, "field": "temp"},
"y": {"type": "quantitative", "aggregate": "count"}
},
"$schema": "https://vega.github.io/schema/vega-lite/v3.2.1.json"
}
Run Code Online (Sandbox Code Playgroud)
我想牛郎星输出到像这样:
{
"config": {"view": {"width": 400, "height": 300}},
"data": {
"url": "https://vega.github.io/vega-datasets/data/seattle-temps.csv"
},
"mark": "bar",
"encoding": {
"x": {"type": "quantitative", "bin": true, "field": "temp"},
"y": {"type": "quantitative", "aggregate": "count"}
},
"$schema": "https://vega.github.io/schema/vega-lite/v3.2.1.json"
}
Run Code Online (Sandbox Code Playgroud)
有没有办法防止 Altair 禁用工具提示?
我们选择禁用自动工具提示,因为 Vega-Lite 将在不久的将来禁用它们。如果您想在特定图表中启用默认工具提示,您可以使用,例如
alt.Chart(data).mark_point(tooltip=alt.TooltipContent('encoding'))
Run Code Online (Sandbox Code Playgroud)
或者
chart.configure_mark(tooltip=alt.TooltipContent('encoding'))
Run Code Online (Sandbox Code Playgroud)
如果您希望会话中的每个图表都包含该设置,您可以创建一个默认启用此设置的Altair 主题。例如:
def tooltips():
return {'config': {'mark': {'tooltip': {'content': 'encoding'}}}}
alt.themes.register('tooltips', tooltips)
alt.themes.enable('tooltips')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
517 次 |
| 最近记录: |