我在目录中有一些 jpeg。我想在一个窗口中以行和列的形式显示它们。例如,如果我有 10 张图片,我想将它们显示为 2 行 5 列的表格。
MATLAB 和 Octave 中有一个 subplot(m, n, k) 命令。我怎样才能在 python 中做类似的事情?
我尝试过使用 PIL.Image 和 show() 方法的枕头,但它非常有限,只能显示 1 张图像。
1- 如何在本地(而不是在浏览器中)执行此操作?
2- 如何使用 matplotlib 做到这一点?
3-如何使用 Jupyter 在浏览器中执行此操作?
import matplotlib.pyplot as plt
from PIL import Image
fig,ax = plt.subplots(2,5)
filenames=['\path\to\img\img_{}.jpg'.format(i) for i in range(10)] #or glob or any other way to describe filenames
for i in range(10):
with open(filenames[i],'rb') as f:
image=Image.open(f)
ax[i%2][i//2].imshow(image)
fig.show()