How can I manipulate the hovertemplate using Sunbust chart?

I’m trying to customize hover information using the below code:

fig = px.sunburst(top_10, path=['Title','Country'], values='Rating', color='Rating',
                  color_continuous_scale='YlGn', title='Highst Rated Movies on Netflix in Each Countries')

fig.update_traces(hovertemplate='Title: %{values} <br>Country: %{}')
fig.show()

I tried to sue %{path[‘Title’]}, hoping it would work but I’m not able to get %{} part working. Is there way to manipulate hover information here?

Thank you in advance!

Hi @sarahekim53
I think you can add hover_data=[‘title’,‘country’] inside you px.sunburst(). Then try something like this:

fig.update_traces(hovertemplate=
        "<b>%{customdata[0]}</b><br><br>" +
         <b>%{customdata[1]}</b><br><br>" +
        "<extra></extra>",
)

Thank you so much, I was struggling with this so much but I see how hover_data works clearly now.

1 Like