`layout` parameter of `plt.figure` can be used for this purpose.
for instance, following example dynamically adjusts the layout to stay tight after window is resized.
import matplotlib.pyplot as plt
x = range(10)
y1 = [i ** 2 for i in x]
y2 = [1.0 / (i + 1) for i in x]
fig = plt.figure(tight_layout=True)
ax1 = plt.subplot(1, 2, 1)
ax1.plot(x, y1)
ax2 = plt.subplot(1, 2, 2)
ax2.plot(x, y2)
plt.show()