我遵循documentation来创建自定义颜色映射。地图我想是这样的:pcolor的自定义颜色映射
这是我想出了字典:
cdict = {'red': ((0.00, 0.0, 0.0),
(0.25, 1.0, 0.0),
(0.50, 0.0, 0.0),
(0.75, 1.0, 0.0),
(1.00, 1.0, 0.0)),
'green': ((0.00, 0.0, 0.0),
(0.25, 1.0, 1.0),
(0.50, 1.0, 1.0),
(0.75, 1.0, 1.0),
(1.00, 0.0, 0.0)),
'blue': ((0.00, 1.0, 1.0),
(0.25, 0.0, 0.0),
(1.00, 0.0, 0.0))
}
但它不给我我想要的结果。例如,值0.5使用红色渲染。
这里是代码的其余部分看起来像:
cmap = LinearSegmentedColormap('bgr', cdict)
plt.register_cmap(cmap=cmap)
plt.pcolor(dist, cmap='bgr')
plt.yticks(np.arange(0.5, len(dist.index), 1), dist.index)
plt.xticks(np.arange(0.1, len(dist.columns), 1), dist.columns, rotation=40)
for y in range(dist.shape[0]):
for x in range(dist.shape[1]):
plt.text(x + 0.5, y + 0.5, dist.iloc[y,x],
horizontalalignment='center',
verticalalignment='center', rotate=90
)
plt.show()
这里所呈现的热图的示例:
我缺少什么?
哦,我看到我得到了彩色地图图像错误。不,这个词是对的,这只是图像必须是反映ti的一面镜子。我只是修正了这一点。问题是.5的值被映射为红色而不是绿色。你提供的文档链接清楚地表明r,g,b条目不需要对齐。在这个例子中,其中一个颜色分量比其他颜色分量有更多的间隔。 –