我正在尝试使用以下代码在Altair中绘制图表。
tot_matches_played = alt.Chart(mpt).mark_bar().encode(
alt.X('Team',axis=alt.Axis(title='Teams Played in IPL'), sort=alt.EncodingSortField(field='Number_of_matches_played:Q', op='count', order='ascending')),
alt.Y('Number_of_matches_played:Q' ),
tooltip=['sum(Number_of_matches_played)']
)
但是由于工具提示名称很怪异,所以我想在图表上使用“ as”重命名它,如下所示。
tot_matches_played = alt.Chart(mpt).mark_bar().encode(
alt.X('Team',axis=alt.Axis(title='Teams Played in IPL'), sort=alt.EncodingSortField(field='Number_of_matches_played:Q', op='count', order='ascending')),
alt.Y('Number_of_matches_played:Q' ),
tooltip=['sum(Number_of_matches_played)' as total_matches]
)
如何重命名工具提示,以便用户在查看图表时可以更容易理解。
答案 0 :(得分:2)
您可以通过title
来调整alt.Tooltip
的输出:
tot_matches_played = alt.Chart(mpt).mark_bar().encode(
alt.X('Team',axis=alt.Axis(title='Teams Played in IPL'), sort=alt.EncodingSortField(field='Number_of_matches_played:Q', op='count', order='ascending')),
alt.Y('Number_of_matches_played:Q' ),
tooltip=[alt.Tooltip('sum(Number_of_matches_played)', title='matches played')]
)
答案 1 :(得分:0)
作为jakevdp答案的附录,如果有人遇到此问题并且需要为两个不同的功能(如我对地图所做的操作)做一个替代标题,则代码的“ tooltip =“部分将像这样工作: / p>
<div class="collection">
<a href="#!" class="collection-item">Alvin</a>
</div>