简体   繁体   English

matplotlib 未在 Jupyter Notebook 上显示图像

[英]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 .我正在使用 ubuntu 14.04 并使用 anaconda2.7 在 jupyter notebook 中编码,其他一切都是最新的。 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这显示在输出区域请帮助

You need to tell matplotlib to actually show the image.您需要告诉 matplotlib 实际显示图像。 Add this at the end of your segment:在段的末尾添加:

plt.show()

To show image in Jupyter Notebook by matplotlib, one should use the %matplotlib inline magic command and plt.show() .要通过 matplotlib 在 Jupyter Notebook 中显示图像,应使用%matplotlib inline魔法命令和plt.show()
As for your code, adding plt.show() after plt.imshow() expression will make the image shown.至于您的代码,在plt.imshow()表达式之后添加plt.show()将使图像显示。

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) .如果您使用notebook后端( %matplotlib notebook ),那么您应该在plt.imshow(img)之前调用plt.figure() plt.imshow(img) This is especially important if you wish to use interactive figures!如果您希望使用交互式图形,这一点尤其重要!

将内核从 xpython 更改为原始 python 内核

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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