Переименовать подсказку в altair - PullRequest
0 голосов
/ 07 сентября 2018

Я пытаюсь построить диаграмму в Альтаире, используя приведенный ниже код.

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]
)

Как переименовать всплывающую подсказку, чтобы она была более понятной для пользователей, просматривающих диаграмму.

Ответы [ 2 ]

0 голосов
/ 30 марта 2019

В качестве дополнения к ответу jakevdp, если кто-то сталкивается с этим и ему нужно сделать альтернативный заголовок для двух различных функций (как я сделал для карты), часть кода "tooltip =" будет работать следующим образом:

tooltip=[alt.Tooltip('properties.feature1:O', title="Feature 1"), alt.Tooltip('properties.feature2:Q', title="Feature 2")]
0 голосов
/ 07 сентября 2018

Вы можете настроить выход 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')]
)
...