I am trying to plot a chart in Altair using the below code.
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)']
)
But since the tooltip name is weird, I would like to rename it on the chart using "as", something like below.
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]
)
How to rename a tooltip so that it would appear in a more readable way to users looking at the chart.
You can adjust the title
output via 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')]
)
As an addendum to jakevdp's answer, if anyone comes across this and needs to do an alternative title for two different features (as I did for a map), the "tooltip=" part of the code will work like this:
tooltip=[alt.Tooltip('properties.feature1:O', title="Feature 1"), alt.Tooltip('properties.feature2:Q', title="Feature 2")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With