2012-07-27 132 views
0

我需要在灰色的色彩地圖中顯示2D矩陣中的數據,但我需要將其定義爲灰度,即白色和黑色不是顏色的最小值和最大值矩陣,以便不會使圖像飽和。我需要的是灰度等級在20%和70%之間的灰度色彩圖,灰度級之間至少有20%的差異。有什麼建議麼? 我正在使用matplotlib的imshow任務表單。在python色彩地圖中設置顏色限制

非常感謝!

回答

0

您可以通過使用您喜歡的顏色創建custom color地圖,或使用imshow中的vmin, vmax關鍵字來強制顏色欄上的大於您想要使用的範圍。

+0

我試過了...但在字典定義,RBG顏色必須從0.0到1.0,所以最後我仍然會有「絕對的」白色廣告黑色......對吧?我嘗試設置vmin = 0.2和vmax = 0.7,並且根本沒有任何變化......即使在imshow參數中norm = None:我該怎麼辦? – manu 2012-07-29 20:13:53

1

你解決了你的問題嗎? 我想這是你想要的,試試這個:

所有代碼pylab模式:

a = np.arange(100).reshape(10,10) 
#here is the image with white and black end 
imshow(a,cmap=mat.cm.binary) 
colorbar() 

#we extract only the 0.2-->0.7 part of original colormap and make a new one 
#so that the white and black end are removed 
rgba_array = mat.cm.binary(np.linspace(0,1,num=10,endpoint=True)) 
extract_rgba_array_255 = rgba_array[2:8,0:3] 
imshow(a,cmap=mat.colors.ListedColormap(extract_rgba_array_255)) 
colorbar()