go.Sunburst not rendering anything

Hi,

I am trying to create a Sunburst plot with the following (obfuscated) data:-

import plotly.graph_objects as go
ids = [β€˜id0’, β€˜id1’, β€˜id2’, β€˜id3’, β€˜id4’, β€˜id5’, β€˜id6’, β€˜id7’, β€˜id8’, β€˜id9’, β€˜id10’, β€˜id11’, β€˜id12’, β€˜id13’, β€˜id14’, β€˜id15’, β€˜id16’, β€˜id17’, β€˜id18’, β€˜id19’, β€˜id20’, β€˜id21’, β€˜id22’, β€˜id23’, β€˜id24’, β€˜id25’, β€˜id26’, β€˜id27’, β€˜id28’, β€˜id29’, β€˜id30’, β€˜id31’, β€˜id32’, β€˜id33’, β€˜id34’, β€˜id35’, β€˜id36’, β€˜id37’, β€˜id38’, β€˜id39’, β€˜id40’, β€˜id41’, β€˜id42’, β€˜id43’, β€˜id44’, β€˜id45’, β€˜id46’, β€˜id47’, β€˜id48’, β€˜id49’]
labels = [β€˜a’, β€˜b’, β€˜c’, β€˜uu’, β€˜e’, β€˜g’, β€˜i’, β€˜k’, β€˜m’, β€˜o’, β€˜aa’, β€˜q’, β€˜s’, β€˜lf’, β€˜bb’, β€˜cc’, β€˜dd’, β€˜ee’, β€˜ff’, β€˜gg’, β€˜hh’, β€˜ii’, β€˜jj’, β€˜kk’, β€˜ll’, β€˜mm’, β€˜lb’, β€˜nn’, β€˜oo’, β€˜d’, β€˜f’, β€˜h’, β€˜j’, β€˜l’, β€˜n’, β€˜p’, β€˜r’, β€˜t’, β€˜u’, β€˜v’, β€˜w1’, β€˜w2’, β€˜x’, β€˜y’, β€˜pp’, β€˜qq’, β€˜v.c’, β€˜z’, β€˜w1’, β€˜x.rr’]
parents = [β€˜β€™, β€˜a’, β€˜b’, β€˜c’, β€˜uu’, β€˜e’, β€˜g’, β€˜i’, β€˜k’, β€˜m’, β€˜o’, β€˜o’, β€˜q’, β€˜s’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜lf’, β€˜s’, β€˜lb’, β€˜lb’, β€˜b’, β€˜d’, β€˜f’, β€˜h’, β€˜j’, β€˜l’, β€˜n’, β€˜p’, β€˜r’, β€˜t’, β€˜u’, β€˜v’, β€˜w1’, β€˜w2’, β€˜x’, β€˜y’, β€˜y’, β€˜u’, β€˜v.c’, β€˜v.c’, β€˜w1’]
text = [β€˜a’, β€˜b’, β€˜c’, β€˜uu’, β€˜e’, β€˜g’, β€˜i’, β€˜k’, β€˜m’, β€˜o’, β€˜aa’, β€˜q’, β€˜s’, β€˜lf’, β€˜bb’, β€˜cc’, β€˜dd’, β€˜ee’, β€˜ff’, β€˜gg’, β€˜hh’, β€˜ii’, β€˜jj’, β€˜kk’, β€˜ll’, β€˜mm’, β€˜lb’, β€˜nn’, β€˜oo’, β€˜d’, β€˜f’, β€˜h’, β€˜j’, β€˜l’, β€˜n’, β€˜p’, β€˜r’, β€˜t’, β€˜u’, β€˜v’, β€˜w1’, β€˜w2’, β€˜x’, β€˜y’, β€˜pp’, β€˜qq’, β€˜v.c’, β€˜z’, β€˜w1’, β€˜x.rr’]
fig = go.Figure(go.Sunburst(labels=labels, parents=parents, text=text, textinfo=β€˜text’, hoverinfo=β€˜text’))
fig.update_layout(margin=dict(t=0, l=0, r=0, b=0))
fig.show()

It is failing because of the w1 entry, which shows up in two different levels of hierarchy. But I thought if unique ids were used for each label, a repeated label would not be a problem. If I add ids=ids to the go.Sunburst arguments, it does not change the outcome. I am using Plotly 5.16.1. Is this a bug or is something formatted incorrectly?

Evening, I had a quick look at this and the part that is missing is you are not sending in any values for the plotly to display.

I reduced your code above and can produce a graph.

import plotly.graph_objects as go

# ids
ids = ['id0', 'id1', 'id2', 'id3', 'id4', 'id5']

# Labels
labels = ['a', 'b', 'c', 'uu', 'e', 'g']

# parents
parents = ['', 'a', 'b', 'c', 'uu', 'e']

# Text
text = ['a', 'b', 'c', 'uu', 'e', 'g']

# Values - I added this to get the graph to show
values = ['1', '2', '3', '4', '5', '6']

# for a sunburst, you need labels, parents, and values
# See - https://plotly.com/python/sunburst-charts/
fig = go.Figure(go.Sunburst(labels=labels, parents=parents, values=values ))

# Update layout for tight margin
fig.update_layout(margin=dict(t=0, l=0, r=1, b=0))

# Display our plot
fig.show()

You will note that I omitted textinfo and hoverinfo as these have been deprecated. you now have hovertemplate and texttemplates

The above produces a graph and as you can see the hoverinfo shows when you hover over an element.

Hopefully, this gives you an idea of how to move on. I always like to start with a small amount of data and prove it’s working first before filing with more data.

1 Like

Hi, twelsh37,

Thanks for checking! Your data avoids what I believe is the root of the problem: repeated labels. If you change your data to instead look like this:-

ids

ids = [β€˜id0’, β€˜id1’, β€˜id2’, β€˜id3’, β€˜id4’, β€˜id5’, β€˜id6’]

Labels

labels = [β€˜a’, β€˜b’, β€˜c’, β€˜uu’, β€˜e’, β€˜g’, β€˜uu’]

parents

parents = [β€˜β€™, β€˜a’, β€˜b’, β€˜c’, β€˜uu’, β€˜e’, β€˜z’]

Text

text = [β€˜a’, β€˜b’, β€˜c’, β€˜uu’, β€˜e’, β€˜g’, β€˜uu’]

Values

values = [β€˜1’, β€˜2’, β€˜3’, β€˜4’, β€˜5’, β€˜6’, β€˜7’]

I am pretty sure you will see the fail-to-render problem. Basically, leaf β€˜uu’ can have a parent named β€˜c’ or β€˜z’. I added ids=ids to the go.Sunburst argument string, but it still failed to render. Is that no longer a viable workaround for situations like this?

Sorry. My brain is fried tonight. I will try and take a look in the morning. I ran your data, and you are correct I did not get a chart rendered.

Just thought I would follow-up on this. It seems that providing unique ids no longer allows one to gracefully deal with repeated label values. Is this a bug? If so, can it be addressed in a future version of plotly? I also tried 5.17.0 today and the outcome was the same.