代码之家  ›  专栏  ›  技术社区  ›  dvd940

Python matplotlib-图像标题不在循环中显示

  •  2
  • dvd940  · 技术社区  · 9 年前

    在下面的函数中 img_list [image, image_title] .

    def display_images(img_list, cmap='gray', cols = 2, fig_size = (10, 10) ):
        """
        Display images in img_list
        """
        i = 1  # for subplot
    
        num_images = len(img_list)
        num_rows = num_images / cols
    
        plt.figure(figsize=fig_size)       
    
        for image in img_list:
            image_file_name = image[1]
            plt.subplot(num_rows, cols, i)        
            plt.title = image_file_name
            plt.imshow(image[0], cmap=cmap)        
            i += 1     
    
        plt.show()
    

    谢谢

    1 回复  |  直到 9 年前
        1
  •  7
  •   ImportanceOfBeingErnest    9 年前

    如果您重新分配 plt.title title() 函数被字符串覆盖。

    相反,你需要 呼叫 这个 plt.title() 作用

    plt.title(image_file_name)