1

I am trying to create a diverging red-green formatting for my pandas dataframe. Specifically, I want any value below 0 to be red, and any value above 0 to be green (& the higher the value, the darker green the cell ... and vice versa).

Currently, I cannot find a way to center this around 0. See below for a quick example of my code and a screenshot of my current output.

Thanks!

rdgn = sns.diverging_palette(h_neg=0, h_pos=112, s=68, l=50, sep=10,n=9, as_cmap=True)
s = test.style.background_gradient(rdgn).set_precision(2)

enter image description here

Michael M
  • 57
  • 8
  • 1
    Normally, with matplotlib you'd use the [`TwoSlopeNorm`](https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.TwoSlopeNorm.html). But here you don't seem to be able to add a norm. As such, you only can set `vmin` and `vmax` to opposite values. E.g. `background_gradient(rdgn, vmin=-0.30, vmax=0.30)`. – JohanC Jan 05 '23 at 10:14
  • Maybe this will help you https://stackoverflow.com/questions/69707509/seaborn-plot-with-colorbar-centered-around-0 – Arkangus Jan 12 '23 at 16:41

0 Answers0