0

I have got couple of images stored as an array using cv2.imread from the folder. I want to now display couple of images from the folder using subplots. Here is what I tried

w=10
h=10
fig=plt.figure(figsize=(8, 8))
columns = 4
rows = 5
for i in range(1, columns*rows +1):
    img = malaria_images[i]
    fig.add_subplot(rows, columns, i)
    plt.imshow(img)
plt.show()

The result however looks like this. I am not sure where I went wrong . Any help would be appreciated. Thank you Image

5
  • Does this Plotting images side by side using matplotlib answer your question? Commented Oct 17, 2020 at 8:23
  • @sai Hi. Thank you for the reply. I tried all the method and it still shows me an empty grids Commented Oct 17, 2020 at 8:49
  • Have you noticed the concept of axes meant as a handle for each subplots? you cannot use plt.imshow Commented Oct 17, 2020 at 8:58
  • Is the content of the 'malaria_images' variable a file path or an image? Commented Oct 17, 2020 at 9:05
  • @r-beginners it is a list of all the images Commented Oct 17, 2020 at 9:26

1 Answer 1

0

I've modified your solution to what is in the comments. Does this not show up?

import matplotlib.pyplot as plt

w=10
h=10
#fig = plt.figure(figsize=(8, 8))
columns = 4
rows = 5

fig, axes = plt.subplots(rows, columns, figsize=(8, 8))

i = 0
for r in range(rows):
    for c in range(columns):
        axes[r,c].imshow(malaria_images[i])
        i += 1

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.