Labeling percentage on each sector in sunburst chart

I made this sunburst chart:

fig =go.Figure(go.Sunburst(
    labels=["Type of Admission", "Other Medical", "Post Surgery", "Adult", "Pediatric",
            "Readmission", "Post Cath", "adult", "pediatric", "Pre-Operative"],
    parents=["","Type of Admission","Type of Admission","Post Surgery","Post Surgery",
             "Type of Admission","Type of Admission","Post Cath","Post Cath","Type of Admission"],
    values=[sum(count.values()),count['Other Medical'],(count['Adult Post Surgery']+count['Pediatric Post Surgery']),
            count['Adult Post Surgery'],count['Pediatric Post Surgery'],
            count['Readmission'],(count['Adult Post Cath']+count['Pediatric Post Cath']),
            count['Adult Post Cath'],count['Pediatric Post Cath'],count['Pre-Operative']],
    textinfo= 'label+value',
    branchvalues= "total"))

fig= fig.update_layout(title_text="Type Of Admission (2019-Q2)",margin = dict(t=0, l=0, r=0, b=0))
fig.show()

I want to label sector percentage from the total. How this could happen?Screenshot (88)

2 Likes

Hello @Mahmoud_Housam, welcome to the forum! You have several possible modes for textinfo, which are Any combination of ['label', 'text', 'value', 'current path', 'percent root', 'percent entry', 'percent parent'] joined with '+' characters (I found this info by giving a mode which was not valid, the error message is actually very informative). For example:

import plotly.graph_objects as go

fig =go.Figure(go.Sunburst(
    labels=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parents=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
    values=[10, 14, 12, 10, 2, 6, 6, 4, 4],
    textinfo='label+percent entry'
))
# Update layout for tight margin
# See https://plot.ly/python/creating-and-updating-figures/
fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))
fig.show()

Hope this helps!

4 Likes

This is great @Emmanuelle !

Do you know if we have something similar for px.sunburst? to show percentage.
Otherwise I will have to reformat my data table into something go.sunburt can accept as un input which I find very complicate and there is no material here show how to do it.

Thanks

2 Likes
fig = px.sunburst(....)
fig.update_traces(textinfo="label+percent")

There you go!

4 Likes

Thank you! you are my hero! :+1:

2 Likes

Thanks @Emmanuelle :heart:

-You can use Any combination of [‘label’, ‘text’, ‘value’, ‘current path’, ‘percent root’, ‘percent entry’, ‘percent parent’] joined with ‘+’ characters
In your case
fig.update_traces(textinfo=“label+value”)

1 Like

Hi, where did you include the dataset in your code? I am trying to build a sunburst graph with a list of values, but I don’t understand where did you add the dataset?

Good morning,
I join this conversation hoping to be helpful to everyone.

How do I, in such a graph, hide the percentage of the parents and keep only the one of children? by setting “label + value” I have the percentages everywhere, I would like only to display the ones of children and keep for relatives only the label.

I hope for your help,
thank you very much
A

1 Like

Hi @aleven - I have the same question than you, did you find a solution?

I would also need to display the textinfo (as percentage) but only at a given layer of the Sunburst - in my case the outer layer.

@empet - I have done some object inspection but I don’t seem to be able to find this textinfo item to update it upon my needs, any ideas? I am using plotly.express.

Hi LouizZanjroz, I didn’t find a solution unfortunately. I finally solved the problem by representing my data differently

1 Like