Image manipulation
Opening images
Matplotlib includes the image module for image manipulation
import matplotlib.image as mpimg
import matplotlib.pyplot as pltImages are read from file (.png only) with the imread function:
img = mpimg.imread('my_image.png')and they are rendered by the imshow function:
plt.imshow(img)Let’s plot the Stack Overflow logo:
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
img = mpimg.imread('so-logo.png')
plt.imshow(img)
plt.show()