I am making a 4 panel plot and was wondering if there is any way to just move the subplot in the bottom left down a bit so it stays in line with the rest of the plots and the titles don't overlay. I believe it is because the bottom left plot doesn't have a colorbar but I'm not sure how I would fix that. I am using the add subplot function. So for the bottom left pot the axes looks like this. ax = fig.add_subplot(2,2,3,projection=proj) 
Move one subplot down
1.3k Views Asked by Wx_Trader At
2
There are 2 best solutions below
0
On
You can use inset_axes in combination with constrained layout:
import matplotlib.pyplot as plt
import numpy as np
fig, axs = plt.subplots(2, 2, layout='constrained')
for i, ax in enumerate(axs.flat):
pcm = ax.pcolormesh(np.random.random((20, 20)) * (i + 1))
ax.set_title("very long title\nthat strechtes over two lines")
if i != 2:
cax = ax.inset_axes([0, -0.35, 1, 0.1])
fig.colorbar(pcm, ax=ax, cax=cax, orientation='horizontal')
See also Placing Colorbars.

I think it might work to read the current position with
ax.get_position(), then move it down a bit withax.set_position(). Something like this:This results in:
As for 'how much?'... Not sure if there's a better way than trial and error though. Not ideal.