Problem with 'percentParent' in Sunburst graphs?

So I’m trying to build a sunburst graph that displays percentParent for each element in the graph. This works fine for all elements except for when I have only a single option for the central node/ring/whatever (see example below)

Since the central node obviously does not have a parent, it appears to bug out and display the bracketed call on percentParent from the texttemplatefield. However, if there are 2 (or more) central nodes, it automatically calculates each’s percentage of the sum total of the two.

My question is:
When I have only 1 central node, how can I either hide this field for the central node only or make it correctly display “100%”?

Example code:

df = pd.DataFrame({'node_names': ['Center', 'Yes', 'No'],
                   'node_parent': ['', 'Center', 'Center'],
                   'node_labels': ['Center', 'Center_Yes', 'Center_No'],
                   'node_counts': [1000, 701, 299]})

fig=go.Figure(
    data=go.Sunburst(
        ids=df.node_names.values,
        labels=df.node_labels.values, 
        parents=df.node_parent.values,
        values=df.node_counts.values,
        branchvalues="total",
        texttemplate = ('%{label}<br>%{percentParent:.1%}'),
    ),
)

fig.show()

It seems to me that here it’s going to be better to add a conditional formatting.

@baobob Any suggestions as to what that might look like in this context?

Here I mean a change of code from plotly dev team. I was exploring fig.data and I couldn’t find a way to update the format in one case only. actually you can pass a list a text format but it looks to me that this is a not ideal solution.

I found this solution. I don’t know how it will work in general.

import pandas as pd
import plotly.graph_objects as go

df = pd.DataFrame({'node_names': ['Center', 'Yes', 'No'],
                   'node_parent': ['', 'Center', 'Center'],
                   'node_labels': ['Center', 'Center_Yes', 'Center_No'],
                   'node_counts': [1000, 701, 299]})

fig=go.Figure(
    data=go.Sunburst(
        ids=df["node_names"],
        labels=df["node_labels"], 
        parents=df["node_parent"],
        values=df["node_counts"],
        branchvalues="total",
        texttemplate = ('%{label}',
                        '%{label}<br>%{percentParent:.1%}',
                        '%{label}<br>%{percentParent:.1%}',
                        '%{label}<br>%{percentParent:.1%}'),
    ),
)

fig.show()
1 Like

I’m having the same issue with this, but my sunburst is dynamic with the selection of drop-downs so sometimes the center slice is single and other times the center is split… I tried unsuccessfully to apply some sort of logic/if statement in the texttemplate, but can’t get this to work.

It also changes the text color of the Sunburst center, which I can’t imagine is intended. This is the only search result I can find on the issues.

Any ideas on this one?

Thanks.

EDIT: Should I report this as an issue on git?

sunburstcode