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]]])

fig.add_trace(go.Treemap(
    labels=df_all_trees['id'],
    parents=df_all_trees['parent'],
    values=df_all_trees['value'],
    text=df_all_trees['color'],
    branchvalues='total',
    marker=dict(
                colors=df_all_trees['norm_value'],
                colorscale=new_dcolorscale,
                # cmid=average_score,
                showscale=True),
    hovertemplate='<b>%{label} </b> <br> PIB: %{value}<br> Inflation: %{color:.2f}',
    textfont=dict(size=16, color=df_all_trees['color_two']),
    name=''
    ), 1, 1)

@spotgamma
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.