Hacker News new | ask | show | jobs
by cs702 1218 days ago
In my experience, `tight_layout` tends to work best after all objects have been drawn:

  fig, axs = plt.subplots(ncols=2, figsize=(6, 3))
  fig.suptitle('Two Made-Up Plots')
  axs[0].plot(np.sinc(np.linspace(-5, 5)))
  axs[1].imshow(np.random.normal(size=(10, 10)))
  fig.tight_layout()  # works really well here!
More here: https://matplotlib.org/stable/tutorials/intermediate/tight_l...

You can also use `constrained_layout`, but in my experience it often doesn't work as well (e.g., the plots end up looking too cluttered for my taste), and also, `constrained_layout` can be noticeably slower (e.g., if you're drawing a large number of complex plots): https://matplotlib.org/stable/tutorials/intermediate/constra...