7

我正在尝试使用以下代码在 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]
)

如何重命名工具提示,以便查看图表的用户以更易读的方式显示它。

4

2 回答 2

9

您可以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')]
)
于 2018-09-07T13:50:08.983 回答
4

作为 jakevdp 答案的附录,如果有人遇到此问题并需要为两个不同的功能做一个替代标题(就像我为地图所做的那样),代码的“工具提示 =”部分将像这样工作:

tooltip=[alt.Tooltip('properties.feature1:O', title="Feature 1"), alt.Tooltip('properties.feature2:Q', title="Feature 2")]
于 2019-03-29T22:05:54.963 回答