0

I used matplotlib.pyplot to plot a list of images [img1, img2, ..., img100], in order to draw them in order, I used plt.subplots to divide the figure area. This is my code:

def show_images(imgs, num_rows, num_cols, titles=None, scale=2, imgText=None, save=False, img_dir=None):  
    figsize = (num_cols * scale, num_rows * (scale))
    _, axes = plt.subplots(num_rows, num_cols, figsize=figsize,frameon =False)
    axes = axes.flatten()
    for i, (ax, img) in enumerate(zip(axes, imgs)):
        img=np.transpose(img * 255, (1, 2, 0))
        ax.imshow(img,cmap='gray')
        ax.axes.get_xaxis().set_visible(False)
        ax.axes.get_yaxis().set_visible(False)
        if not titles is None:
            ax.set_title(titles[i])
    plt.show()
    return axes

The resulting figure is here. But I wasn't able to put a main title on the plt.subplots figure. How can I achive that so that it looks like this?

FBruzzesi
  • 6,385
  • 3
  • 15
  • 37
Klian
  • 3
  • 1
  • 3

1 Answers1

-1

Have you tried just titling the plot itself?

plt.title("Your title here")

My recollection is that if you do this before you call subplot, it'll title the whole thing.

N Tracey
  • 31
  • 4