My subplot results

My code
fig,ax = plt.subplots(rows,cols, figsize = [24,24])
plt.subplots_adjust(hspace=0, wspace=0)
for i in range(cols):
step = 6
ind = i*step
ax[0,i].imshow(a[ind,:,:],cmap='gray')
ax[0,i].axis('off')
ax[1,i].imshow(b[ind,:,:],cmap='gray')
ax[1,i].axis('off')
ax[2,i].imshow(c[ind,:,:],cmap='gray')
ax[2,i].axis('off')
However, it seems like plt.subplots_adjust(hspace=0, wspace=0) not working at all. I notice that it forces the figure to have equal x and y size, could you help me correct this?
You may either shrink the figure size in vertical direction, e.g.
fig,ax = plt.subplots(rows,cols, figsize = [24,12])
or you may keep the square figure size but put more margin around the subplots
plt.subplots_adjust(bottom=0.3, top=0.7, hspace=0)
The ratio in figsize should be same as the ratio of rows and cols in plt.subplot(rows, cols, figsize). For example, if rows is 2 and cols is 4, then the ratio is 1/2, thus figsize being (15, 7.5)(same ratio) would be good.
Following code is an example.
fig, ax = plt.subplots(2, 4, figsize=(15, 7.5))
for i in range(2):
for j in range(4):
img = cv2.cvtColor(cv2.imread(os.path.join('../input/deepfake486326facescleaned', train_df.loc[i*2+j, 'name_path'])), cv2.COLOR_BGR2RGB)
ax[i][j].imshow(img)
ax[i][j].set_title(train_df.loc[i*2+j, 'label'])

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With