我正在尝试使用下面的代码在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]
)如何重命名工具提示,使其对查看图表的用户更具可读性。
发布于 2018-09-07 21:50:09
您可以通过alt.Tooltip调整title输出
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')]
)发布于 2019-03-30 06:05:55
作为对jakevdp答案的补充,如果有人遇到这种情况,并且需要为两个不同的功能(就像我对地图所做的那样)做一个替代标题,代码的"tooltip=“部分将如下所示:
tooltip=[alt.Tooltip('properties.feature1:O', title="Feature 1"), alt.Tooltip('properties.feature2:Q', title="Feature 2")]https://stackoverflow.com/questions/52223358
复制相似问题