Python imshow() 函数不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16460442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:42:06  来源:igfitidea点击:

imshow() function not working

pythonmatplotlib

提问by user2129468

I'm working on a program in python with packages numpy,scipy and matplotlib.pyplot. This is my code:

我正在用 python 编写一个程序,其中包含 numpy、scipy 和 matplotlib.pyplot 包。这是我的代码:

import matplotlib.pyplot as plt
from scipy import misc
im=misc.imread("photosAfterAverage/exampleAfterAverage1.jpg")
plt.imshow(im, cmap=plt.cm.gray)

for some reason the image isn't showing up (checked if I got the image, in that part it's all fine- I can print the array.).

出于某种原因,图像没有显示出来(检查我是否得到了图像,在那部分一切正常——我可以打印数组。)。

回答by tiago

You need to call plt.show()to display the image. Or use ipython --pylabfor an interactive shell that is matplotlibaware.

您需要调用plt.show()以显示图像。或ipython --pylab用于可matplotlib感知的交互式 shell 。

回答by Remi Cuingnet

"Interactive mode may also be turned on via matplotlib.pyplot.ion(), and turned off via matplotlib.pyplot.ioff()" cf. matplotlib user guide.

“交互模式也可以通过打开matplotlib.pyplot.ion()和关闭matplotlib.pyplot.ioff()参见。matplotlib 用户指南