✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Treemap Custom scale color scale

Hi Everyone,

I am new in Dash and Plotly environnement, great tools !

I am currently working on Treemap. So far I successfully read my excel, extract data and buil a hierarchical dataframe to be read by plotly Treemap ( go.Treemap).

I am now struggling to create a custom colorscale based on a custom scale. For example data < -2 = Red color / -2< data < -1 = Yellow / -1< data < 1 = Green color etc etc

And this part is so difficult. I have read that pltly read only normalized data for the scale, so I did normalized my column in my dataframe, I normalized too my scale regarding to my dataframe. Can’t succeed in this… I end up with purple gradient color.

Do you have any documentation, or example regarding custom colorscale based on custom intervals ?

This is the fig.add_trace part, what am I mising, or what do you need to see more to better understand this issue ?

It feels so strange that it’s so difficul to implement custom simple scale.

colors = [’#DF432C’, ‘#DFCF2C’ , ‘#53AE27’]
new_dcolorscale = #discrete colorscale
for k in range(len(colors)):
new_dcolorscale.extend([[new_bvals[k], colors[k]], [new_bvals[k+1], colors[k]]])

                # cmid=average_score,
    hovertemplate='<b>%{label} </b> <br> PIB: %{value}<br> Inflation: %{color:.2f}',
    textfont=dict(size=16, color=df_all_trees['color_two']),
    ), 1, 1)

This thread [Colors for discrete ranges in heatmaps]
(Colors for discrete ranges in heatmaps)
on discrete colorscale contains a link to a Jupyter Notebook that gives a function to define such a colorscale.