亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在python中從文件中繪制多個圖像?

如何在python中從文件中繪制多個圖像?

慕工程0101907 2022-06-22 16:20:53
我正在嘗試從 jupyter notebook 中的文件繪制多個圖像。圖像已顯示,但它們在一個列中。我在用著:%matplotlib inlinefrom os import listdirform PIL import image as PImagefrom matplotlib import pyplot as pltdef loadImages(path):    imagesList = listdir(path)    loadedImages = []    for image in imagesList:        img = PImage.open(path+image)        LoadedImages.append(img)        Return loadedImagespath = 'C:/Users/Asus-PC/flowers/'imgs = loadImages(path)for img in imgs    plt.figure()    plt.imshow(img)我希望它們出現在網格布局(行和列)中。部分問題是我不知道 add_subplot 的參數是什么意思。我怎樣才能做到這一點?
查看完整描述

2 回答

?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

您可以使用,matplotlib但顯示大量圖像往往非常緩慢且效率低下。因此,如果您想更快、更輕松地完成此操作 - 我建議您使用我的名為IPyPlot的包:


import ipyplot


ipyplot.plot_images(images_list, max_images=20, img_width=150)

它支持以下格式的圖像:

-string文件路徑

-PIL.Image對象

-numpy.ndarray表示圖像的對象


它能夠在大約 70 毫秒內顯示數百張圖像


查看完整回答
反對 回復 2022-06-22
?
侃侃爾雅

TA貢獻1801條經驗 獲得超16個贊

您可以使用創建多個子圖plt.subplots。確定加載圖像的列數和行數。就像是:


from os import listdir

import matplotlib.pyplot as plt


path = 'C:/Users/Asus-PC/flowers/'

imagesList = listdir(path)

n_images = len(imagesList)    


figure, axes = plt.subplots(n_images, 1)   # (columns, rows)    

for ax, imgname in zip(axes, imagesList):  # Iterate over images and

        img = plt.imread(path+imgname)     # axes to plot one image on each.

        ax.imshow(img)                     # You can append them to an empty

                                           # list if you need them later.

plt.show()


查看完整回答
反對 回復 2022-06-22
  • 2 回答
  • 0 關注
  • 216 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號