Displaying image with matplotlib in ipython

cerebrou picture cerebrou · Feb 24, 2016 · Viewed 20.2k times · Source

How can I display an image imported with numpy package using matplotlib in ipython?

It should be fairly easy with the command

import numpy as np
import matplotlib.pyplot as plt

im = np.array(Image.open('image.jpg'))

plt.imshow(im)

But the image does not show and I just get the output

<matplotlib.image.AxesImage at 0x7fb38e10ff10>

Answer

Hannes Ovr&#233;n picture Hannes Ovrén · Feb 24, 2016

You must call plt.show() to actually bring up the windows. You can get around this by using interactive mode. But for scripts it is better to simply call show() after completing all your plotting commands.