【问题标题】:Open a PNG in Jupyter Notebook在 Jupyter Notebook 中打开 PNG
【发布时间】:2019-07-30 20:56:29
【问题描述】:

我正在尝试使用此代码在 jupyter notebook 中使用 python 打开图像。

这是代码:

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)

并且给了我这个错误:

ValueError Traceback(最近调用 最后)在 3 4 # 读取图片 ----> 5 img = mpimg.imread('C:/Users/alvar/Desktop/IE/1 - Full-time/Term 2/Machine Learning 2/Assigments/Group/For 星期日/坦桑尼亚.png') 6 7 # 输出图片

~\Anaconda3\lib\site-packages\matplotlib\image.py in imread(fname, 格式)1373 其他:1374 带打开(fname, 'rb') 作为 fd: -> 1375 返回处理程序(fd) 1376 其他:1377 返回处理程序(fname)

ValueError: 无效的 PNG 标头

【问题讨论】:

标签: python jupyter-notebook png jupyter


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-07-31
    • 2023-02-04
    • 2018-11-27
    • 2019-05-17
    • 2020-04-23
    • 2020-07-13
    • 2022-11-11
    • 1970-01-01
    • 2020-10-17
    相关资源
    最近更新 更多