1

I've 2 subplots in a single row. Below is the code:-

plt.suptitle('Water Vapor Count for Fani before landfall') #Overall plot title.

fig,(ax1,ax2)=plt.subplots(nrows=1,ncols=2,figsize=(15,15)) #Defining the figure and axes
image_wv_global=ax1.imshow(wvcount,vmin=800,vmax=975,label="Global") #First image
plt.colorbar(image_wv_global,ax=ax1,fraction=0.046, pad=0.04) #Colorbar for first image, declaring the axis in it is v.imp.

image_wv_asia=ax2.imshow(wvcount,vmin=800,vmax=975,label="Asia specific") #Second image
plt.axis([300, 1000, 200, 700])  #Axis restriction for asia-specific plot
plt.colorbar(image_wv_asia,fraction=0.046,ax=ax2, pad=0.04) #Colorbar for 2nd subplot

ax1.title.set_text('Global plot') #1st subplot title
ax2.title.set_text('Asia-specific plot') #2nd subplot title
ax1.grid()
ax2.grid()

fig.suptitle('Main title',ha='center',va='bottom')
#fig.tight_layout()
plt.show()

Everything is working fine except that there's a unwanted huge gap between the main plot-title and the 2 subplots as shown in this image.

I've tried setting the alignment for matplotlib.suptitle using ha=center and va=top but to no avail. Even using va=bottom or va=baseline isn't working.

Any suggestions?

Pixel_Bear
  • 97
  • 1
  • 1
  • 11

1 Answers1

1

This is how I am getting after generating some random data: Plot

Just by deleting this row:

plt.suptitle('Water Vapor Count for Fani before landfall') #Overall plot title.

and modified this row:

fig.suptitle('Main title',ha='center',va='bottom')

to:

fig.suptitle('Water Vapor Count for Fani before landfall')
aliwimo
  • 156
  • 2
  • 8
  • Thank you for your effort. Unfortunately, for some reason it's not working for me. I just realized that I mistakenly put two ```suptitle()```. I corrected it to just ```fig.suptitle("Main title")``` but there's something I must be missing, since the problem still persists. – Pixel_Bear Jul 03 '22 at 16:46
  • Update: - In the asia-specific plot, I made the range of x and y axes equal. I was suspecting that this asymmetry is creating this problem. But it's not the case. – Pixel_Bear Jul 04 '22 at 08:06
  • Update: - I put ```y=0.7``` inside the ```fig.suptitle()``` and got it fixed. It's now positioned just like your output. Once again, thank you for your effort. – Pixel_Bear Jul 04 '22 at 08:12