How to map number to color using matplotlib’s colormap?

It’s as simple as cm.hot(0.3):

import matplotlib.cm as cm
    
print(cm.hot(0.3))
(0.8240081481370484, 0.0, 0.0, 1.0)

If you also want to have the normalizer, use

import matplotlib as mpl
import matplotlib.cm as cm
   
norm = mpl.colors.Normalize(vmin=-20, vmax=10)
cmap = cm.hot
x = 0.3

m = cm.ScalarMappable(norm=norm, cmap=cmap)
print(m.to_rgba(x))
(1.0, 0.8225486412996345, 0.0, 1.0)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)