Using matplotlib.colors.LinearSegmentedColormap
's from_list
method seems more intuitive than some of the other answers here.
from matplotlib.colors import LinearSegmentedColormap
cmap=LinearSegmentedColormap.from_list('rg',["r", "w", "g"], N=256)
Or for more sophisticated tuning:
from matplotlib.colors import LinearSegmentedColormap
c = ["darkred","red","lightcoral","white", "palegreen","green","darkgreen"]
v = [0,.15,.4,.5,0.6,.9,1.]
l = list(zip(v,c))
cmap=LinearSegmentedColormap.from_list('rg',l, N=256)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…