简体   繁体   中英

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. When I use subplot method, the displayed image size is decreasing in some way. 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:

在此处输入图片说明

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.

If you're looking for faster and more efficient way of plotting images in notebooks you should consider using ipyplot

import ipyplot

ipyplot.plot_images(X_train, img_width=150)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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