【问题标题】:how to display more than 1 image on google colab如何在google colab上显示超过1张图片
【发布时间】:2021-01-14 08:57:46
【问题描述】:

如何在 google colab 上显示多于 1 张图片

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))

我试过这个脚本,但它不起作用

【问题讨论】:

标签: python


【解决方案1】:

如果要在每一行中显示,则将plt.show() 放在plt.imshow() 下方

如果您想以类似网格的形式显示,请使用subplot

会是这样的(会显示在一行中):

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)

或者

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

【讨论】:

    猜你喜欢
    • 2016-04-16
    • 2019-05-13
    • 2022-12-08
    • 1970-01-01
    • 2013-06-11
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 2022-01-14
    相关资源
    最近更新 更多