Usama Khan
Usama Khan

Reputation: 371

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

Upvotes: 27

Views: 78127

Answers (5)

Kunal Kumar
Kunal Kumar

Reputation: 1

Open your ipython config file, or create it if it doesn't exist:

ipython profile create
cd ~
cd ~/.ipython
cd profile_default/
vim ipython_config.py

Uncomment the line containing TerminalIPythonApp.gui and remove space as shown below. Remove None and put qt5 in single quotes:

c.TerminalIPythonApp.gui = 'qt5'

Open your virtual environment folder (mine is - python_virtual_environment):

cd python_virtual_environment

Activate your venv and install qt5 in the virtual environment:

source venv/bin/activate
pip install PyQt5

Open ipython again, and it will work.

If it still doesn't work, try searching for InteractiveShellApp.gui in vim normal mode:

/InteractiveShellApp.gui

and replace None with 'qt5'.

Upvotes: 0

Sailist
Sailist

Reputation: 164

change kernel from xpython to original python kernel

Upvotes: 1

jmsinusa
jmsinusa

Reputation: 1652

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!

Upvotes: 11

yann
yann

Reputation: 662

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.

Upvotes: 17

Graham S
Graham S

Reputation: 1702

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

plt.show()

Upvotes: 40

Related Questions