Hi guys,
I came across the following problem. I would like to create a sunburst chart with a hole in the middle. I wanted to do so using a single root, which I could color white in the end.
Furthermore, I would like to do it with the grapical_objects sunburst function rather than the plotly.express function. However, I used the plotly.express function to create parents, labels and values. For the graphical object version I constructed an id because I have duplicate values for the children in the outer ring.
However the neither I donโt get a result shown for the graphical_object version โfig2โ. The express version โfig1โ is working as intended.
Do you have an idea what I could try to make it work with the graphical object. Essentially the goal is a white hole in the middle and I need to allow duplicates in the children.
df = pd.DataFrame({"Country": ["Country1", "Country2", "Country2", "Country1"], "side": ["buy", "sell", "buy", "sell"],
"constant": ["CONST", "CONST", "CONST", "CONST"], "trading_volume_eur": [600, 500, 300, 400]})
path_values = ["constant", "Country", "side"]
fig = px.sunburst(df, path=path_values, values="trading_volume_eur")
fig.show()
labels = fig['data'][0]['labels'].tolist()
parents = fig['data'][0]['parents'].tolist()
values = fig['data'][0]['values'].tolist()
ids = [f"id{x}" for x in range(len(labels))]
fig2 = go.Figure(
go.Sunburst(
# ids=ids,
labels=labels,
parents=parents,
values=values,
branchvalues='total',
# rotation=90,
# insidetextorientation='horizontal'
))
fig2.show()
fig1: