matplotlib.pyplot 和 ipython 或 python 图像不显示

Image does not show with matplotlib.pyplot with ipython or python

如果我在 iPython 或 Python 中执行以下命令,

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img=mpimg.imread('stinkbug.png')
imgplot = plt.imshow(img)

然后什么也没有发生(没有图像出现在任何地方)。

但是如果我执行以下命令:

import scipy.misc as misc
img=misc.imread('stinkbug.png')
misc.imshow(img)

然后图像出现在 ImageMagick 的单独 window 中。

此外,我可以 运行 ipython 使用 qtconsole 并且将看到带有第一个代码的图像。

两种不同的图片显示方式有什么区别?它们能否统一,即在两个控制台中以类似的方式工作?是否可以使第一个代码正常工作 ipython/python?

在代码末尾添加 plt.show(imgplot)

缺少一行显示情节window:

plt.show()