'How to put a main title of the subplots on plt.subplots? [duplicate]
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?
Solution 1:[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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | N Tracey |
