Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to invert matplotlib pyplot pcolor cmap

To illustrate my question, I will generate a simple heatmap.

import matplotlib.pyplot as plt
import numpy as np

heatmap = np.asarray([[20, 0, 40],
                      [0, 40, 40],
                      [20, 40, 50]])

heatmap_plot = plt.pcolor(heatmap, cmap='RdBu', vmin=0, vmax=100)
plt.show()

This produces the following image;

enter image description here

Here, one can see that the lower values appear as darker red, and the larger values approach white. How do i reverse this setting? I other words, how do I make lower values lighter shades (0 = white). and larger values represent darker colors, in this case, red.

I couldn't seem to find any such parameter looking at the pcolor documentation.

like image 215
Malonge Avatar asked Sep 15 '25 14:09

Malonge


1 Answers

Just add _r to your cmap. Your new cmap is RdBu_r.

like image 85
Conor Avatar answered Sep 17 '25 04:09

Conor