3

How to force min and max value range when styling a dataframe column ?

Example :

df = pd.DataFrame(columns = ['column'], data = [-1, 0, 1, 2])
df.style.background_gradient(cmap='coolwarm_r')

This produces a column where value 0 is red ; however I would like 0 to be white, i.e. the middle of the 'coolwarm' colormap.

In this example, my understanding of the problem is that the default colormap interval maps my data [-1 : 2].

I would like to set it to [-2 : 2]

1 Answer 1

1

You can set the vmin and vmax as follows:

df.style.background_gradient(cmap='coolwarm_r', vmin=-2, vmax=2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.