简体   繁体   English

在Jupyter Notebook中打开PNG

[英]Open a PNG in Jupyter Notebook

Im trying this code to open an image in a jupyter notebook with python. 我正在尝试此代码以使用python在jupyter笔记本中打开图像。

This is the code: 这是代码:

import matplotlib.image as mpimg 
import matplotlib.pyplot as plt 

# Read Images 
img = mpimg.imread('C:/Users/alvar/Desktop/IE/1 - Full-time/Term 2/Machine Learning 2/Assigments/Group/For sunday/Tanzania.png') 

# Output Images 
plt.imshow(img)

And is giving me this error: 并给我这个错误:

ValueError Traceback (most recent call last) in 3 4 # Read Images ----> 5 img = mpimg.imread('C:/Users/alvar/Desktop/IE/1 - Full-time/Term 2/Machine Learning 2/Assigments/Group/For sunday/Tanzania.png') 6 7 # Output Images 3中的ValueError Traceback(最近一次通话最近)4#读取图像----> 5 img = mpimg.imread('C:/ Users / alvar / Desktop / IE / 1-全日制/学期2 /机器学习2 / Assigments / Group / For Sunday / Tanzania.png')6 7#输出图像

~\\Anaconda3\\lib\\site-packages\\matplotlib\\image.py in imread(fname, format) 1373 else: 1374 with open(fname, 'rb') as fd: -> 1375 return handler(fd) 1376 else: 1377 return handler(fname) 〜\\ Anaconda3 \\ lib \\ site-packages \\ matplotlib \\ image.py in imread(fname,format)1373 else:1374 with open(fname,'rb')as fd:-> 1375 return handler(fd)1376 else:1377返回处理程序(fname)

ValueError: invalid PNG header ValueError:无效的PNG标头

如果您只是在Jupyter笔记本中插入png以供参考,则可以考虑利用markdown单元并使用以下代码:

<img src=“path_to_image/image.png”>

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

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