Matplotlib 可以使用 subplot 或 subplots 方法来创建子图,从而在同一窗口中显示多张图片。以下是一些示例代码,展示如何使用 Matplotlib 显示多张图片:
1.使用 subplot
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
# 读取图片
img1 = mpimg.imread('path_to_image1.jpg')
img2 = mpimg.imread('path_to_image2.jpg')
# 创建一个新的图形
plt.figure()
# 添加第一个子图
plt.subplot(1, 2, 1