Flip/reverse colour legend when formatting table

Hi @TristanSun

I’ll answer the question here since the code is in this post. To summarize you wanted extreme colors on each end in red and green in the middle.

This colorscale is not currently defined in the colorlover library, however you can provide your own colors for the scale. If you look at line 36 you will see where the background colors are generated with the colorlover utiity:

backgroundColors = colorlover.scales[str(n_bins)]["div"]["RdYlGn"]

If you print(backgroundColors) you will see that it returned a list of evenly spaced colors based on the “`RdYlGn’” colorscale

['rgb(215,48,39)', 'rgb(252,141,89)', 'rgb(254,224,139)', 'rgb(255,255,191)', 'rgb(217,239,139)', 'rgb(145,207,96)', 'rgb(26,152,80)']

You could rearrange the colors - or change them to whatever colors you like. For example if you used:

backgroundColors = ['rgb(215,48,39)', 'rgb(252,141,89)', 'rgb(145,207,96)', 'rgb(26,152,80)', 'rgb(145,207,96)', 'rgb(252,141,89)',  'rgb(215,48,39)']

The scale in the above example would be:

image

1 Like