Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Set individual colors based on value of cell in plotly table

I am trying to create a table with monthly returns of a stock. Want to fill the cell with red if negative values and green if positive values. Any help on how to do this would be appreciated. I can only find references to use a color scale.

@chhab Here is an eaxample on how to fill the cells according to their values:
https://plot.ly/~empet/14689.

If you want to use a colorscale adapted to the values in a column cells, like in this heatmap https://plot.ly/~empet/14685, then take a look at this notebook: http://nbviewer.jupyter.org/github/empet/Plotly-plots/blob/master/Plotly-asymmetric-colorscales.ipynb.
Once you have defined the adapted colorscale, normalize each value in a column and associate to the normalized value, let us say 0.73, that falls in the interval [0.7, 0.8], thelinearly interpolated color, from the rgb colors corresponding to 0.7, and 0.8 in the Plotly assymetric colorscale.

1 Like

Thanks empet. That worked!!!

Thank you this was very helpful. In case someone else comes across this and wants to add more than one color for conditional formatting in the table here is the code below that you would insert into the first example listed. My scale is different but you get the idea. Two else statements is a bit strange but it works.

[‘rgb(235,249,39)’ if val >=0.10 and val<= 0.17 else ‘rgb(0,250,0)’ if val <=0.10 else ‘rgb(250,0,0)’ for val in vals

1 Like