我想在不同的图中使用不同的颜色图显示图像.
以下代码显示具有两个不同窗口但具有相同颜色映射的图像
import scipy.misc
from pylab import *
a = scipy.misc.imread('lena.jpg')
figure(1)
image = mean(a,axis=2)
imshow(image)
#if I call show() here then only one window is displayed
gray() #change the default colormap to gray
figure(2)
imshow(image)
show()
Run Code Online (Sandbox Code Playgroud)
我想知道是否有人可以帮助我.
非常感谢.
您可以将cmap
参数传递给imshow函数.请看http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.imshow
要做子图,请使用subplot
命令(!)
要更改色彩映射,可以使用函数的cmap
参数imshow
.请参阅文档.
figure() # You don't need to specify 1
subplot(121) # 121 is a shortcut for 1 line, 2 columns, item number 1
image = mean(a,axis=2)
imshow(image, cmap='gray')
subplot(122) # 1 line, 2 columns, item number 2
imshow(image, cmap='jet')
show()
Run Code Online (Sandbox Code Playgroud)