0

I want to display multiple images at once in one figure (i used a set of 22 images so for the subplot i used 5 rows and 5 columns) , but the problem is they display one by one every time i close the figure, here is how i did it :

import cv2
import glob
import matplotlib.pyplot as plt



path="data/*.jpg"

images=[cv2.imread(image) for image in glob.glob(path)]
fig=plt.figure()
for i in range(len(images)):
    plt.subplot(5,5,i+1)
    plt.imshow(images[i])
    plt.show()
John
  • 5
  • 1
  • 3

2 Answers2

0

The problem is you are displaying the plot within the loop, and should display it after you have placed all the images.

Move plt.show() outside the loop.

RufusVS
  • 4,008
  • 3
  • 29
  • 40
0

Here's how to plot multiple images with matplotlib and opencv:

import cv2
import glob
import matplotlib.pyplot as plt



path="data/*.jpg"


images=[cv2.imread(image) for image in glob.glob(path)]
fig, ax = plt.subplot(len(5))

for i in range(len(images)):
    image = plt.imread(images[i])
    ax[i].imshow(image)

plt.show()