【发布时间】:2019-05-03 13:51:28
【问题描述】:
我正在尝试将文件夹中的每张图片连同它们的文件名一起绘制为标题,但我似乎做不到。
我试过这个代码,但是文件名都是一样的(它们是列表中最终图像的所有名称,由于迭代问题)。
# Put all images in the folder into a list (works)
images = []
for f in glob.iglob("/content/testing_data/Bad/*"):
images.append(np.asarray(Image.open(f)))
# plot the images (works)
images = np.array(images)
fig, axs = plt.subplots(15, 5, figsize=(10, 50))
fig.subplots_adjust(hspace = .3, wspace=.3)
axs = axs.ravel()
# This is for displaying the names (works)
for filename in os.listdir('/content/testing_data/Bad/'):
RatName = filename[:-4]
# show the filename (this bit doesn't work)
for i in range(len(images)):
axs[i].imshow(images[i])
axs[i].set_title(RatName)
我希望它将图像绘制为以文件名作为标题的子图...
文件名1,文件名2,文件名3
但我明白了:
文件名3,文件名3,文件名3
【问题讨论】:
标签: python python-3.x matplotlib