How to Show an Image using Matplotlib in Python?

In this post, I'm going to talk about how to display an image with matplotlib. Let's dive in!

 


First I'm going to use the PIL library to open the image. PIL is the Python Imaging Library that adds image processing capabilities to your Python interpreter.

Let's import the Image function to open our image.




 
Let's open the image from our google drive and enter the path of the image.



Let's convert this image into a numpy array. First, I'm going to import the numpy library.

 


After that let's convert the image into a numpy array.

 


 Let's take a look at the shape of this array. 



Now, let's see the image using matplotlib. I'm going to import matplotlib first.



Let's create a new figure object and enter a figure size.

 


Let's add a subplot to the figure.



Finally, let's display the image with the imshow method.

 


You will see a image like below:

 


You can watch the video of this tutorial below 👇


Thank you for reading. I hope you enjoy it. You can find the notebook I used in this article here.

Don't forget to follow me on Twitter | Youtube | Medium | Instagram for more tips, tricks and guides about data science, machine learning, deep learning, and cloud computing.