Plotly.express - Sunburst - Remove elements from the hover data?

Is there any way to remove some of the default headings from the sunburst ‘hover data’. For instance below, I would like to remove ‘labels’, ‘parent’ and ‘id’, only leaving ‘Total Heat Loss (kWh)’ and ‘Area / Length’.

image

I have tried the hover_data parameter within the sunburst set up, however this only removes columns within the dataframe I have fed in.

Thanks in advance.

1 Like

Hi @BenArnold
Try to use hovertemplate. More information in the docs.

import plotly.express as px
df = px.data.tips()
fig = px.sunburst(df, path=['day', 'time', 'sex'], values='total_bill')
fig.update_traces(hovertemplate='<b>the total bill is: %{value} </b>')  # parent, or label, or id, or value
fig.show()
2 Likes

Hi Adam,

Thanks so much for the answer, yes I think I tried this however see the error I get when using hover_data as a dictionary:

Have I misunderstood it?

Thanks!

Hi @BenArnold . I just updated my answer. hove_data is for other graphs type. I forgot that’s it’s different for the sunburst. Let me know if that worked for you.

2 Likes

@BenArnold
To change the default hovertemplate defined by px.sunburst, you must update the sunburst trace setting your own hovertemplate:
Example:

import plotly.express as px
data = dict(
    character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
    value=[10, 14, 12, 10, 2, 6, 6, 4, 4])

fig = px.sunburst(
    data,
    names='character',
    parents='parent',
    values='value',
)
fig.show()

print(fig.data[0]) to inspect the hovertemplate definition and redefine it according to your aim:

fig.update_traces(hovertemplate="My own label: %{value}<extra></extra>")
1 Like