【问题标题】:How can I plot 4000 images line by line in jupyter notebook?如何在 jupyter notebook 中逐行绘制 4000 张图像?
【发布时间】:2023-03-26 12:15:01
【问题描述】:

我想逐行绘制 4000 张图像作为子图或使用其他方法。当我使用 subplot 方法时,显示的图像大小以某种方式减小。我想解决这个问题并了解导致绘图大小减小的原因,或者学习其他绘制图像的方法。

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

Jupyter notebook 的结果:

【问题讨论】:

    标签: python matplotlib jupyter-notebook


    【解决方案1】:
    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()
    

    我已将“ix+1”更改为“1”,问题已解决,因为 for 循环会导致 jupyter notebook 中的新行用于绘图。

    【讨论】:

      【解决方案2】:

      如果您正在寻找在笔记本中更快、更有效地绘制图像的方法,您应该考虑使用ipyplot

      import ipyplot
      
      ipyplot.plot_images(X_train, img_width=150)
      

      【讨论】:

        猜你喜欢
        • 2016-10-10
        • 1970-01-01
        • 1970-01-01
        • 2018-11-06
        • 2018-11-15
        • 2019-10-14
        • 2018-12-10
        • 2017-07-07
        • 2019-03-22
        相关资源
        最近更新 更多