第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決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)我希望它們出現(xiàn)在網(wǎng)格布局(行和列)中。部分問題是我不知道 add_subplot 的參數(shù)是什么意思。我怎樣才能做到這一點(diǎn)?
查看完整描述

2 回答

?
開滿天機(jī)

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個贊

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


import ipyplot


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

它支持以下格式的圖像:

-string文件路徑

-PIL.Image對象

-numpy.ndarray表示圖像的對象


它能夠在大約 70 毫秒內(nèi)顯示數(shù)百張圖像


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

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超16個贊

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


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


查看完整回答
反對 回復(fù) 2022-06-22
  • 2 回答
  • 0 關(guān)注
  • 224 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號