Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maptplotlib imshow() does nothing [duplicate]

I recently installed Anaconda distribution (with sudo, under /usr/lib).

However, when trying to execute the following lines:

from matplotlib import pyplot
from numpy import zeros
pyplot.imshow(zeros((100, 100)))

Nothing happens (I expect to see a black screen). No error at all.

What am I missing?

like image 355
Luis Masuelli Avatar asked Jan 29 '16 13:01

Luis Masuelli


People also ask

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.

Does Imshow normalize image?

By default, imshow normalizes the data to its min and max. You can control this with either the vmin and vmax arguments or with the norm argument (if you want a non-linear scaling).

How does Matplotlib Imshow work?

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


1 Answers

You need to tell matplotlib to show the plot (or save the figure to a file) after making it.

To display the plot on the screen, try adding pyplot.show() after your imshow line.

To save to a file, try pyplot.savefig('myfig.png')

like image 157
tmdavison Avatar answered Sep 24 '22 16:09

tmdavison