Display multiple images in one IPython Notebook cell?

后端 未结 10 1420
面向向阳花
面向向阳花 2020-12-12 12:26

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

10条回答
  •  北海茫月
    2020-12-12 13:13

    from matplotlib.pyplot import figure, imshow, axis
    from matplotlib.image import imread
    
    mypath='.'
    hSize = 5
    wSize = 5
    col = 4
    
    def showImagesMatrix(list_of_files, col=10):
        fig = figure( figsize=(wSize, hSize))
        number_of_files = len(list_of_files)
        row = number_of_files/col
        if (number_of_files%col != 0):
            row += 1
        for i in range(number_of_files):
            a=fig.add_subplot(row,col,i+1)
            image = imread(mypath+'/'+list_of_files[i])
            imshow(image,cmap='Greys_r')
            axis('off')
    
    showImagesMatrix(listOfImages,col)
    

    based on @Michael answer

提交回复
热议问题