0

Im trying this code to open an image in a jupyter notebook with python.

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

~\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)

ValueError: invalid PNG header

  • Possible duplicate of [matplotlib: ValueError: invalid PNG header](https://stackoverflow.com/questions/39379609/matplotlib-valueerror-invalid-png-header) – liamhawkins Mar 08 '19 at 19:35

1 Answers1

0

If you are just inserting a png just for reference in a Jupyter notebook you could consider taking advantage of a markdown cell and using the following code:

<img src=“path_to_image/image.png”>
FChm
  • 2,515
  • 1
  • 17
  • 37