matplotlib – Display an image with Python

matplotlib – Display an image with Python

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()

If you use matplotlib, you need to show the image using plt.show() unless you are not in interactive mode.
E.g.:

plt.figure()
plt.imshow(sample_image) 
plt.show()  # display it

matplotlib – Display an image with Python

In a much simpler way, you can do the same using

from PIL import Image

image = Image.open(image.jpg)
image.show()

Leave a Reply

Your email address will not be published. Required fields are marked *