Go Treemap does not render

Hello Everyone,
I created a Treemap using plotly express from the dataframe below and its working as expected

sum

The following is my code and output Treemap

fig = px.treemap( summary_df,path=[‘ANALYSISMETHOD’,‘NAME’], values=‘COUNT’)
fig.update_layout(
margin = dict(t=50, l=25, r=25, b=25))
fig.show()

I need to recreate this Treemap using plotly.graph_objects, mainly to use it in a subplot and have more control.
The problem is the go treemap never displays and I am not sure why.
Here is the Go Treemap code

import plotly.graph_objects as go
parents_list=[‘’]+summary_df[‘ANALYSISMETHOD’].values.tolist()
fig = go.Figure(go.Treemap(
labels = summary_df[“NAME”].values.tolist(),
parents = parents_list,
values= summary_df[“COUNT”].values.tolist(),
root_color=“lightgrey”,
textinfo =“label+value”
))
print (fig)
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig.show()

Here is what the fig looks when i print it

Can anyone advise on what I am missing here ? I have been troubleshooting for hours.

Thank you

Hello Everyone,
After investigating this further, it seems that in order to create a GO Treemap for recursive data we have to construct a data frame with a certain structure. The screen below shows a data frame that was engineered from the simpler data frame that was used by the express treemap .

I used the code below to create the go tree data frame.

treemap_df = pd.DataFrame(columns = [‘ids’, ‘labels’, ‘parents’,‘count’])
#process analysis_summary_df
for index,row in analysis_summary_df.iterrows():
treemap_df = treemap_df.append({‘ids’ : row[‘ANALYSISMETHOD’], ‘parents’ : “total”, ‘count’ :row[‘COUNT’] , ‘labels’:row[‘ANALYSISMETHOD’]},ignore_index = True)

#add total record
total_value=analysis_summary_df[‘COUNT’].sum()
treemap_df = treemap_df.append({‘ids’ : “total”, ‘parents’ : “”, ‘count’ :total_value , ‘labels’:“total”},ignore_index = True)

#process name_summary_df
for index,row in name_summary_df.iterrows():
id=row[‘ANALYSISMETHOD’]+“-”+row[‘NAME’]
treemap_df = treemap_df.append({‘ids’ : id, ‘parents’ : row[‘ANALYSISMETHOD’], ‘count’ : row[‘COUNT’], ‘labels’:row[‘NAME’]},ignore_index = True)

Once I had the data frame ready, I was able to create the go treemap using the code below

go_treemap= go.Treemap(
labels = treemap_df.labels,
ids=treemap_df.ids,
parents =treemap_df.parents,
root_color=“lightgrey”,
values=treemap_df[‘count’],
branchvalues=‘total’,
textinfo = “label+value+percent parent+percent entry”,
hovertemplate=‘%{label}
Count: %{value}

)

Regards,
Ihab