简体   繁体   English

如何在 jupyter notebook 中逐行绘制 4000 张图像?

[英]How can I plot 4000 images line by line in jupyter notebook?

I would like to plot 4000 images line by line as a subplot or with another method.我想逐行绘制 4000 个图像作为子图或使用其他方法。 When I use subplot method, the displayed image size is decreasing in some way.当我使用 subplot 方法时,显示的图像大小以某种方式减小。 I would like to fix that and understand what causes decreasing in plotting size, or learn the other ways to plot images.我想解决这个问题并了解导致绘图尺寸减小的原因,或者学习其他绘制图像的方法。

for ix in range(0, len(preds_train_t)):
    fig = plt.figure()
    #ix = random.randint(0, len(preds_train_t))
    fig.add_subplot(ix+1, 3, 1) 
    plt.imshow(np.dstack((X_train[ix],X_train[ix],X_train[ix])))   

    tmp = np.squeeze(Y_train[ix]).astype(np.float32)
    fig.add_subplot(ix+1, 3, 2) 
    plt.imshow(np.dstack((tmp,tmp,tmp)))

    tmp = np.squeeze(preds_train_t[ix]).astype(np.float32)
    fig.add_subplot(ix+1, 3, 3) 
    plt.imshow(np.dstack((tmp,tmp,tmp)))
    plt.show()

results of Jupyter notebook: Jupyter 笔记本的结果:

在此处输入图片说明

for ix in range(0, len(preds_train_t)):
        fig = plt.figure()
        #ix = random.randint(0, len(preds_train_t))
        fig.add_subplot(1, 3, 1) 
        plt.imshow(np.dstack((X_train[ix],X_train[ix],X_train[ix])))   

        tmp = np.squeeze(Y_train[ix]).astype(np.float32)
        fig.add_subplot(1, 3, 2) 
        plt.imshow(np.dstack((tmp,tmp,tmp)))

        tmp = np.squeeze(preds_train_t[ix]).astype(np.float32)
        fig.add_subplot(1, 3, 3) 
        plt.imshow(np.dstack((tmp,tmp,tmp)))
        plt.show()

I have changed the "ix+1" to "1" and problem has been solved as for loop causes new line in jupyter notebook for plotting.我已将“ix+1”更改为“1”,问题已解决,因为 for 循环导致 jupyter notebook 中的新行用于绘图。

If you're looking for faster and more efficient way of plotting images in notebooks you should consider using ipyplot如果您正在寻找在笔记本中绘制图像的更快、更有效的方法,您应该考虑使用ipyplot

import ipyplot

ipyplot.plot_images(X_train, img_width=150)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM