Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imshow() function not working

I'm working on a program in python with packages numpy,scipy and matplotlib.pyplot. This is my code:

import matplotlib.pyplot as plt from scipy import misc im=misc.imread("photosAfterAverage/exampleAfterAverage1.jpg") plt.imshow(im, cmap=plt.cm.gray) 

for some reason the image isn't showing up (checked if I got the image, in that part it's all fine- I can print the array.).

like image 408
user2129468 Avatar asked May 09 '13 11:05

user2129468


People also ask

Why is Imshow not showing PLT?

plt. imshow just finishes drawing a picture instead of printing it. If you want to print the picture, you just need to add plt. show .

What is PLT Imshow ()?

The matplotlib function imshow() creates an image from a 2-dimensional numpy array. The image will have one square for each element of the array. The color of each square is determined by the value of the corresponding array element and the color map used by imshow() .

How do I show multiple images on Imshow?

imshow always displays an image in the current figure. If you display two images in succession, the second image replaces the first image. To view multiple figures with imshow , use the figure command to explicitly create a new empty figure before calling imshow for the next image.


1 Answers

You need to call plt.show() to display the image. Or use ipython --pylab for an interactive shell that is matplotlib aware.

like image 138
tiago Avatar answered Sep 23 '22 20:09

tiago