I am new to Plotly I am trying to specify the colour green for positive digit and red for negative on a heatmap.

Tried different ways but no luck in final figure. When I print, i can see the colour getting assigned in dataframe properly but only picks up the default colour in the figure output.

Here is my code:

custom_colorscale = [[float("%.1f" % (1/v)),'rgb(255,0,0)'] if v<0
else [float("%.1f" %  (1/v)),'rgb(0,255,0)'] for v in heatmap]

HM = go.Heatmap(z=[df_table['A'].tolist(), df_table['B'].tolist()],
                x=df_table['dates'].tolist(),
                y=['Asset A','Asset B'],
                xaxis='x3',
                yaxis='y3',
                colorscale=custom_colorscale,
                connectgaps=True,
                colorbar=dict(len=0.53,
                              y=0.25),) # padding xgap = 2,ygap = 2,

custom_colorscale = [[float("%.1f" % (1/v)),'rgb(255,0,0)'] if v<0
else [float("%.1f" %  (1/v)),'rgb(0,255,0)'] for v in heatmap]

HM = go.Heatmap(z=[df_table['A'].tolist(),df_table['B'].tolist()],
                x=df_table['dates'].tolist(),
                y=['Asset A','Asset B'],                                                 
                xaxis='x3',
                yaxis='y3',
                colorscale=custom_colorscale,
                connectgaps=True,
                colorbar=dict(len=0.53,
                              y=0.25),)

0 Answers