在python中并排绘制两个图像

2024-06-07 00:16:19 发布

您现在位置:Python中文网/ 问答频道 /正文

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

enter image description here

在Matlab中,我相信这可以使用imshow([I1,I2])完成,但是matplotlib的PythonAPI不接受图像数组。在python中有这样做的方法吗?


Tags: 方法图像图形pythonapi关系matplotlib绘制数组
1条回答
网友
1楼 · 发布于 2024-06-07 00:16:19

如果使用numpy,只需使用numpy concatenate函数生成一个表示两个图像的大数组:

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

相关问题 更多 >