2014-02-21 28 views
1

我在Debian上使用Python 2.7.5。 cmap=plt.cm.gray究竟做了什麼?如果灰色表示灰度彩色圖,那麼我怎麼能使用這個命令顯示彩色圖像?Python Colormap

plt.imshow(im,cmap=plt.cm.gray) 

回答

3

你可能正在提供imshowMxNx3陣列,然後將其解釋並且顯示爲RGB圖像。提供然後簡單地忽略任何CMAP,考慮這個例子:

image = np.random.rand(10,10,3) 

fig, axs = plt.subplots(1,2, figsize=(8,6)) 

axs[0].set_title('RGB image with gray cmap') 
axs[0].imshow(image, interpolation='none', cmap=plt.cm.gray) 

axs[1].set_title('Single layer image with gray cmap') 
axs[1].imshow(image[:,:,0], interpolation='none', cmap=plt.cm.gray) 

enter image description here

+1

我忘記 「* * CMAP時,忽略* X *具有RGB(A)信息」 中的文檔 – zhangxaochen

相關問題