Image titles not displaying in loop

Question:

I wish to display images in a loop with the image name as a title. Each image displays in the loop but the title does not.

In the function below, the img_list contains lists with the following [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()
Asked By: dvd940

||

Answers:

If you reassign plt.title, the title() function is overwritten by a string.

Instead you need to call the plt.title() function.

plt.title(image_file_name)
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.