Zet*_*tor 1 python image matplotlib ipython jupyter-notebook
我在目录中有一些 jpeg。我想在窗口中按行和列显示它们。例如,如果我有 10 张图片,我想将它们显示为 2 行 x 5 列的表格。
MATLAB 和 Octave 中有一个 subplot(m, n, k) 命令。我如何在 python 中做类似的事情?
我已经尝试过使用 PIL.Image 和 show() 方法的枕头,但它非常有限并且只显示 1 个图像。
1-如何在本机(不在浏览器中)执行此操作?
2-如何使用 matplotlib 做到这一点?
3-如何使用 Jupyter 在浏览器中执行此操作?
小智 7
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()
Run Code Online (Sandbox Code Playgroud)