我遵循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條目不需要對齊。在這個例子中,其中一個顏色分量比其他顏色分量有更多的間隔。 –