使用Python显示图像 [英] Display an image with Python
本文介绍了使用Python显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将IPython.display与以下代码一起使用:
I tried to use IPython.display with the following code:
from IPython.display import display, Image
display(Image(filename='MyImage.png'))
我也尝试使用matplotlib以下代码:
I also tried to use matplotlib with the following code:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
plt.imshow(mpimg.imread('MyImage.png'))
在这两种情况下,都不会显示任何内容,甚至没有错误信息。
In both cases, nothing is displayed, not even an error message.
推荐答案
如果您正在使用matplotlib并希望在交互式笔记本中显示图像,请尝试以下操作:
If you are using matplotlib and want to show the image in your interactive notebook, try the following:
%pylab inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img=mpimg.imread('your_image.png')
imgplot = plt.imshow(img)
plt.show()
这篇关于使用Python显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文