1

how to display more than 1 image on google colab

from google.colab import files
from keras.preprocessing import image

uploaded = files.upload()
for fn in uploaded.keys():
  path = fn
  img = image.load_img(path, target_size=(150,150))

I've tried this script but it doesn't work

mfahmifadh
  • 87
  • 1
  • 10
  • This do not display image but upload it to your folders. – Pdeuxa Jan 14 '21 at 09:02
  • I try to upload 3 image using uploaded = files.upload(), but when i show image with imgplot = plt.imshow(img), only 1 image show – mfahmifadh Jan 14 '21 at 09:04
  • 1
    this will help: https://stackoverflow.com/questions/48435229/how-to-plot-a-list-of-image-in-loop-using-matplotlib . you can use subplot – Pygirl Jan 14 '21 at 09:07
  • 1
    Does this answer your question? [How to plot a list of image in loop using matplotlib?](https://stackoverflow.com/questions/48435229/how-to-plot-a-list-of-image-in-loop-using-matplotlib) – Pygirl Jan 14 '21 at 09:08
  • how to use it with uploaded.files? – mfahmifadh Jan 14 '21 at 09:12

1 Answers1

1

If you to display in each line then put plt.show() below the plt.imshow()

If you want to display in form like grid then use subplot

It will be like this(will display in a single row):

from google.colab import files
from keras.preprocessing import image
import matplotlib.pyplot as plt

uploaded = files.upload()
fig = plt.figure(figsize=(10,10))
for num, fn in enumerate(uploaded.keys()):
  path = fn
  img = image.load_img(path, target_size=(150,150))
  plt.subplot(1,len(uploaded),num+1) # <-------
  plt.axis('off')
  plt.imshow(img)

Or

for fn in uploaded.keys():
  fig = plt.figure(figsize=(10,10))
  path = fn
  img = image.load_img(path, target_size=(150,150))
  plt.axis('off')
  plt.imshow(img)
  plt.show() #<------------here
Pygirl
  • 12,969
  • 5
  • 30
  • 43