Dims
Dims

Reputation: 51039

Image does not show with matplotlib.pyplot with ipython or python

If I do the following commands in iPython or just Python,

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img=mpimg.imread('stinkbug.png')
imgplot = plt.imshow(img)

then nothing happens (no image appear anywhere).

But if I do the following commands:

import scipy.misc as misc
img=misc.imread('stinkbug.png')
misc.imshow(img)

then image appears inside separate window of ImageMagick.

Also, I can run ipython with qtconsole and will see image with first code.

What are the difference between two different ways of diplaying images? Can they be unified, i.e. work in similar way in both consoles? Is it possible to make first code work in normal ipython/python?

Upvotes: 1

Views: 728

Answers (2)

AlessioX
AlessioX

Reputation: 3177

Add plt.show(imgplot) at the end of your code.

enter image description here

Upvotes: 1

Andreas Müller
Andreas Müller

Reputation: 212

One line is missing to show the plot window:

plt.show()

Upvotes: 1

Related Questions