简体   繁体   中英

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, ie work in similar way in both consoles? Is it possible to make first code work in normal ipython/python?

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

在此处输入图片说明

缺少一行显示绘图窗口:

plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM