Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting two images side by side in python

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?

like image 293
Marc Khoury Avatar asked Nov 17 '25 11:11

Marc Khoury


1 Answers

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()
like image 171
jusx Avatar answered Nov 20 '25 00:11

jusx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!