【问题标题】:Tooltips in stacked Altair/Vega-Lite chart disappear when using interval selections使用间隔选择时,堆叠 Altair/Vega-Lite 图表中的工具提示消失
【发布时间】:2020-03-01 10:15:12
【问题描述】:

Altair 示例库包含 a nice example 如何使用区间选择来创建两个图,其中一个允许您定义另一个的比例。我一直在尝试通过将工具提示定义为基础的一部分来向堆叠图表的两个部分添加工具提示:

import altair as alt
from vega_datasets import data

source = data.sp500.url

brush = alt.selection(type='interval', encodings=['x'])

base = alt.Chart(source).mark_area().encode(
    x = 'date:T',
    y = 'price:Q',
    tooltip = 'price:Q'
).properties(
    width=600,
    height=200
)

upper = base

lower = base.properties(
    height=60
).add_selection(brush)

upper & lower

这样做,工具提示在lower 上按预期工作,但在upper 上则完全不工作。

但是,如果我从lower 中删除.add_selection(brush),则工具提示也适用于upper(未更改),但这当然违背了示例的目的。我还可以通过将其标记为交互式来使工具提示在upper 上工作,但同样,这会破坏该示例的优点。将upper 的定义更改为upper = base.encode(tooltip='price:Q') 没有任何作用。

如何定义工具提示目标以使工具提示同时显示在upperlower 上?

【问题讨论】:

    标签: python data-visualization vega-lite altair


    【解决方案1】:

    工具提示停止工作的事实可能是一个错误,值得提交Vega-Lite bug report

    看来您可以通过向上方图表添加第二个空选项来解决此问题:

    upper = base.add_selection(alt.selection_single())
    

    您可以查看互动结果here

    【讨论】:

    • 谢谢;在我的情况下,这种解决方法应该可以完成工作。我添加了bug report
    • 其实,这几乎有效,但我注意到当悬停在底部图表的实际选择中的数据时,工具提示仍然无效'不行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-21
    • 2021-04-12
    • 2017-08-17
    • 1970-01-01
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多