Display multiple images in one IPython Notebook ce

2019-01-21 04:07发布

If I have multiple images (loaded as NumPy arrays) how can I display the in one IPython Notebook cell?

I know that I can use plt.imshow(ima) to display one image… but I want to show more than one at a time.

I have tried:

 for ima in images:
     display(Image(ima))

But I just get a broken image link:

enter image description here

8条回答
狗以群分
2楼-- · 2019-01-21 04:39

This is easier and works:

from IPython.display import Image
from IPython.display import display
x = Image(filename='1.png') 
y = Image(filename='2.png') 
display(x, y)
查看更多
Summer. ? 凉城
3楼-- · 2019-01-21 04:43

Horizontal layout

Horizontal layout demonstration

Short answer

plt.figure(figsize=(20,10))
columns = 5
for i, image in enumerate(images):
    plt.subplot(len(images) / columns + 1, columns, i + 1)
    plt.imshow(image)

Long answer

import glob
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
%matplotlib inline

images = []
for img_path in glob.glob('images/*.jpg'):
    images.append(mpimg.imread(img_path))

plt.figure(figsize=(20,10))
columns = 5
for i, image in enumerate(images):
    plt.subplot(len(images) / columns + 1, columns, i + 1)
    plt.imshow(image)
查看更多
登录 后发表回答