[英]Altair - making legend interactive
使用以下代碼:
highlight = alt.selection(type='single', on='mouseover',
fields=['For Team'], nearest=True)
# The basic line
base = alt.Chart(df_teams_full_stats).mark_line(interpolate='basis').encode(
x='GameWeek:Q',
y='Goals:Q',
color=alt.Color('Color', scale=None),
tooltip=['For Team:N', 'Goals:Q']
)
points = base.mark_circle().encode(
opacity=alt.value(0)
).add_selection(
highlight
).properties(
width=600
)
lines = base.mark_line().encode(
size=alt.condition(~highlight, alt.value(0.5), alt.value(3.5))
)
我可以 plot 我的所有行並在“鼠標懸停”處突出顯示每一行,如下所示:
現在我想更改此選擇模式,而不是鼠標懸停,而是通過單擊團隊圖例來綁定選擇突出顯示,如下例所示:
https://altair-viz.github.io/gallery/interactive_legend.html
如何調整上面的代碼以達到這種效果?
您可以通過將選擇綁定到圖例來創建交互式圖例,如您鏈接到的示例所示:
highlight = alt.selection_single(fields=['For Team'], bind='legend')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.