Reorder categorical variable in plotly's treemap

Viewed 35

Based on the code provided here, I reproduced the figure below. However, I would like to reorder the days of the week to appear in order: Thursday, Friday, and Sunday. How do you change that in plotly treemap? I appreciate your kind help.

import plotly.express as px

df = px.data.tips()
fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'], 
                 values='total_bill', color='time')
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig.show()

I thought adding fig.update_traces(sort=False) would do the job but it didn't order it with the natural order of the weeks(Thursday, Friday, Saturday, Sunday). I think that is probably done with a dictionary but I didn't manage to make it work.

enter image description here

0 Answers
Related