Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib not displaying image on Jupyter Notebook

I am using ubuntu 14.04 and coding in jupyter notebook using anaconda2.7 and everything else is up to date . Today I was coding, every thing worked fine. I closed the notebook and when I reopened it, every thing worked fine except that the image was not being displayed.

%matplotlib inline
import numpy as np
import skimage
from skimage import data
from matplotlib import pyplot as plt
%pylab inline

img = data.camera()
plt.imshow(img,cmap='gray')

this is the code i am using, a really simple one but doesn't display the image

<matplotlib.image.AxesImage at 0xaf7017ac>

this is displayed in the output area please help

like image 330
Usama Khan Avatar asked Sep 09 '16 16:09

Usama Khan


4 Answers

You need to tell matplotlib to actually show the image. Add this at the end of your segment:

plt.show()
like image 156
Graham S Avatar answered Oct 31 '22 00:10

Graham S


To show image in Jupyter Notebook by matplotlib, one should use the %matplotlib inline magic command and plt.show().
As for your code, adding plt.show() after plt.imshow() expression will make the image shown.

like image 23
yann Avatar answered Oct 31 '22 00:10

yann


If using the inline backend, you just need to call plt.show().

If you are using the notebook backend (%matplotlib notebook), then you should call plt.figure() before plt.imshow(img). This is especially important if you wish to use interactive figures!

like image 33
jmsinusa Avatar answered Oct 31 '22 01:10

jmsinusa


change kernel from xpython to original python kernel

like image 21
Sailist Avatar answered Oct 31 '22 01:10

Sailist