首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在altair中重命名工具提示

在altair中重命名工具提示
EN

Stack Overflow用户
提问于 2018-09-07 21:15:09
回答 2查看 2.2K关注 0票数 7

我正在尝试使用下面的代码在Altair中绘制一个图表。

代码语言:javascript
复制
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“将其重命名,如下所示。

代码语言:javascript
复制
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]
)

如何重命名工具提示,使其对查看图表的用户更具可读性。

EN

回答 2

Stack Overflow用户

发布于 2018-09-07 21:50:09

您可以通过alt.Tooltip调整title输出

代码语言:javascript
复制
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')]
)
票数 9
EN

Stack Overflow用户

发布于 2019-03-30 06:05:55

作为对jakevdp答案的补充,如果有人遇到这种情况,并且需要为两个不同的功能(就像我对地图所做的那样)做一个替代标题,代码的"tooltip=“部分将如下所示:

代码语言:javascript
复制
tooltip=[alt.Tooltip('properties.feature1:O', title="Feature 1"), alt.Tooltip('properties.feature2:Q', title="Feature 2")]
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52223358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档