Question about Treemap and sunburst chart of Plotly Express.The color_discrete_map of parameters is not work

I am a student and I want to use plotly.express to make a dashboard for my homework.I want to unify the colors of the company In every chart.So I use color_discrete_map to set color for each company.but it is not working in Treemap and sunburst chart.

For example:
#-----------------------------------------------------------------

df = pd.DataFrame({‘company’:[“Java”,“mongoDB”,“Python”,“C++”],
‘popularity’:[99,50,100,50]})
colors = {“Java”:‘orange’,“mongoDB”:“Red”,“Python”:“yellow”,“C++”:“green”}
px.treemap(df,path = [‘company’],values=“popularity”,color = “company”,color_discrete_map = colors).show()
px.bar(df,x = ‘company’,y=“popularity”,color = “company”,color_discrete_map = colors)

#-------------------------------------------------------------------------
In this code The color for each company of treemap does not followed color_discrete_map ,but color of bar chart has followed followed color_discrete_map

This problem has troubled me for several days.

Hope guys can help me. Thank you

Hi @Cmccm123, welcome to the forum! There was indeed a bug which we have fixed in plotly 4.5.1, which we released last week. Could you please try to upgrade to the latest version and see if the problem is solved?

oh !thank you! this is work

1 Like

@Emmanuelle I use 4.8.1 and seems the bug is still there. The color_discrete_map that I used, does not work with px.treemap but works with px.bar. I want to unify the colors in both charts, but I am unable to. Please help! Thank you!