在 python 中并排绘制两个图像

Plotting two images side by side in python

我想使用 matplotlib 在 Python 中并排绘制两个图像。但是我不想创建单独的子图。我想在同一张图中绘制两个图像,以便我可以绘制两个图像之间的对应关系。见下图。

在 Matlab 中,我相信这可以使用 imshow([I1, I2]) 来完成,但是 matplotlib 的 python API 不接受图像数组。在 python 中有没有办法做到这一点?

如果您使用 numpy,您可以使用 numpy 连接函数简单地创建一个表示两个图像的大数组:

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()