Python matplotlib 未在 Jupyter Notebook 上显示图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39416004/
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
matplotlib not displaying image on Jupyter Notebook
提问by Usama Khan
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.
我正在使用 ubuntu 14.04 并使用 anaconda2.7 在 jupyter notebook 中编码,其他一切都是最新的。今天我在编码,一切正常。我关闭了笔记本,当我重新打开它时,除了没有显示图像外,一切正常。
%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
这显示在输出区域请帮助
回答by Graham S
You need to tell matplotlib to actually show the image. Add this at the end of your segment:
您需要告诉 matplotlib 实际显示图像。在段的末尾添加:
plt.show()
回答by yann
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.
要通过 matplotlib 在 Jupyter Notebook 中显示图像,应使用%matplotlib inline
魔术命令和plt.show()
.
至于您的代码,添加plt.show()
afterplt.imshow()
表达式将使图像显示。
回答by jmsinusa
If using the inline
backend, you just need to call plt.show()
.
如果使用inline
后端,您只需要调用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!
如果您正在使用notebook
后端 ( %matplotlib notebook
),那么您应该plt.figure()
在plt.imshow(img)
. 如果您希望使用交互式图形,这一点尤其重要!