python - 如何使用 python 在表格中显示多个 jpeg 图像?

标签 python image matplotlib ipython jupyter-notebook

<分区>

我在目录中有一些 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()

关于python - 如何使用 python 在表格中显示多个 jpeg 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52592829/

相关文章:

python - 无法导入模块 'lambda_function' : No module named 'stomp'

c# - 使用 opentok 获取视频的快照图像

python - 使用seaborn深色主题并删除条形图中条形之间的间隙

Python 单元测试 : AttributeError: no attribute 'assertTrue' when running on Linux

Python - 使用 lxml 将 urlib2 替换为 Requests

python - 在 Pandas 中应用列

python - pathlib.Path.home() 中的 pathlib 库错误 : type object 'Path' has no attribute 'home'

css - 在 ul (菜单)之间放置图像

javascript - 如何将html页面设置为背景图片?

python - 无边界 matplotlib 图