Sunburst Chart - Percentages don't add to 100%

Hello all,

I am working on a sunburst chart, and am finding that the total percentage of the inner pie chart does not always add up to 100%, dependent on the data (sometimes 101%, other times 99% - dependent on the data).

Has anyone else had the problem? (I am very new so could be very simple).

Thanks!

Ben

Hi @BenArnold ! Welcome to the forum :blush:

My guess is that it’s just a rounding error. Some of the numbers probably have been rounded up (for ex, 25% is actually 24.6% and 19% is 18.8%). Probably if you add the percentages with decimal positions the result will be 100%.

Hope this helps! :four_leaf_clover:

Hi Celia,

Thanks for the answer, that is what I suspected. Is there any way to ensure this central pie adds to 100%, I am trying to role this out, and am sure that this minor detail will be picked up on.

Thanks for your help!!

Ben

I guess you are using the textinfo=β€˜text+percent-root’ argument. You can change what is shown in the text of each piece by using the texttemplate argument, which overrides textinfo: https://plotly.com/python/reference/sunburst/#sunburst-texttemplate

If your figure is called fig that can be done like this:
fig.update_traces(texttemplate = '%{label}<br>%{percentRoot:.2%}')

In that case, you would have the name and the percentage with two decimals (ex. 25.78%). If you wanted only one decimal position it would be {percentRoot:.1%}' and so on.

I think that would solve it :slight_smile:

1 Like