Skip to content
Advertisement

Centering a background gradient color map for a pd.DataFrame Styler object

Unsure if it is possible to leverage matplotlib’s DivergingNorm for color maps under the framework of pandas Styler objects. As an example:

JavaScript

enter image description here

Ideally only negative (positive) values would appear red (green).

Advertisement

Answer

It doesn’t look like there is an option to pass a custom normalization to background_gradient (maybe could be a feature request to post on pandas github). But you can use a custom function to get the desired result:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement