To display different images with actual size in a Matplotlib subplot, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Read two images using imread() method (im1 and im2)
- Create a figure and a set of subplots.
- Turn off axes for both the subplots.
- Use imshow() method to display im1 and im2 data.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
im1 = plt.imread("bird.jpg")
im2 = plt.imread("opencv-logo.png")
fig, ax = plt.subplots(nrows=1, ncols=2)
ax[1].axis('off')
ax[1].imshow(im1, cmap='gray')
ax[0].axis('off')
ax[0].imshow(im2, cmap='gray')
plt.show()Output
