我建议你自己定制颜色图来解决这个问题from matplotlib.colors import LinearSegmentedColormap
data = np.array([[1, 0, 0, 1],
[0, 0, 1, 1],
[0, 0, 0, 1]])
colorInformation = np.array([[0.1, 0.12, 0.02, 0.01],
[0.12, 0.15, 0.18, 0.2],
[0.3, 0.34, 0.41, 0.32]])
alpha_up=abs(((data*2-1)*colorInformation).max())
alpha_low=abs(((data*2-1)*colorInformation).min())
mid=alpha_low/(alpha_up+alpha_low)
cdict1 = {'red': ((0.0, 1.0, 1.0),
(mid, 1.0, 0.0),
(1.0, 0.0, 0.0)),
'green': ((0.0, 0.0, 0.0),
(1.0, 0.0, 0.0)),
'blue': ((0.0, 0.0, 0.0),
(mid, 0.0, 1.0),
(1.0, 1.0, 1.0)),
'alpha': ((0.0, alpha_low, alpha_low),
(mid, 0.0, 0.0),
(1.0, alpha_up, alpha_up))
}
red_blue = LinearSegmentedColormap('red_blue', cdict1)
fig, ax = plt.subplots()
heatmap = ax.pcolormesh((data*2-1)*colorInformation, cmap=red_blue)
或者你可以只改变红色和蓝色而不用阿尔法通道。在