Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display images using different color maps in different figures in matplotlib?

I want to display images using different color maps in different figures.

Following code displays the image with two different windows but the same color map

   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()

I am wondering if anyone can please help me.

Thanks a lot.

like image 923
Shan Avatar asked Jul 20 '11 21:07

Shan


People also ask

How do I show multiple images in matplotlib?

Create random data using numpy. Add a subplot to the current figure, nrows=1, ncols=4 and at index=1. Display data as an image, i.e., on a 2D regular raster, using imshow() method with cmap="Blues_r".


1 Answers

To do subplots, use the subplot command (!)

To change the colormap, you can use the cmap argument of the imshow function. See the documentation.

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()
like image 84
Simon Avatar answered Nov 11 '22 12:11

Simon