Plotting two images side by side in python

10,286

If you use numpy you can simply make one large array that represents the two images using the numpy concatenate function:

import numpy as np
import matplotlib.pyplot as plt

img_A = np.ones((10,10))
img_B = np.ones((10,10))

plot_image = np.concatenate((img_A, img_B), axis=1)

plt.imshow(plot_image)
plt.show()
Share:
10,286
Marc Khoury
Author by

Marc Khoury

Updated on June 04, 2022

Comments

  • Marc Khoury
    Marc Khoury almost 2 years

    I'd like to plot two images side by side in Python using matplotlib. However I don't want to create separate subplots. I want to plot two images in the same figure so that I can draw correspondences between the two images. See image below.

    enter image description here

    In Matlab I believe this can be done using imshow([I1, I2]) however the python API for matplotlib does not accept an array of images. Is there a way to do this in python?