8

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>
cerebrou
  • 5,353
  • 15
  • 48
  • 80
  • 2
    Possible duplicate of [Use imshow of matplotlib.pylab with a python ide?](http://stackoverflow.com/questions/34742842/use-imshow-of-matplotlib-pylab-with-a-python-ide) – MB-F Feb 24 '16 at 07:57

2 Answers2

15

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.

Hannes Ovrén
  • 21,229
  • 9
  • 65
  • 75
6

In IPython or Jupyter notebooks, if you want to show images as inline in the notebook and not in a separate window, implement the code shown below.

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

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

plt.imshow(im)
plt.show()
r4ghu
  • 75
  • 2
  • 6