如何使用matlib函数plt.imshow(image)显示多个图像? [英] How do I use the matlib function plt.imshow(image) to display multiple images?
本文介绍了如何使用matlib函数plt.imshow(image)显示多个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def exiacc():
global my_img, readimg , im, list_name, exis_img, tkimage
print('Opening Existing Account...')
topl = Toplevel()
readimg = './facedata/'
list_img = os.listdir(readimg)
row, col = 0, 0
k = 0
for fn in os.listdir(readimg):
if fn.endswith('.jpg'):
list_name.append(fn[:fn.index('_')])
im = Image.open(os.path.join(readimg, fn))
im2 = im.resize((200, 200), Image.LANCZOS)
tkimage = ImageTk.PhotoImage(im2)
exis_img = Label(topl, image=tkimage)
exis_img.grid(row = row + 1, column = col + 1, padx=2, pady=2)
exis_name = Label(topl, text = list_name[k] , font = ("consolas", 12, "bold"))
exis_name.grid(row=row + 2, column = col + 1, padx=2, pady=2)
col += 1
k +=1
if col == 5:
row += 2
col = 0
我的结果表明,只有最后处理过的图像才能有效覆盖其他图像.
My results show that only the last processed image is shown effectively overwriting the other images.
推荐答案
一个直接的解决方案是改用plt.subplots:
A straight forward solution would be to use plt.subplots instead:
import numpy as np
import matplotlib.pyplot as plt
lst_cmaps = ['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn']
data = ((np.arange(100) % 10) * np.arange(100)).reshape(10, 10)
nxn = int(np.sqrt(len(lst_cmaps)))
plt, ax = plt.subplots(nxn, nxn)
for i, ax_ in enumerate(ax.flatten()):
ax_.imshow(data, cmap=lst_cmaps[i])
这会给你一个这样的图像:
This gives you an image like this:
这篇关于如何使用matlib函数plt.imshow(image)显示多个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文