constrained_layout + fixed-aspect axes + bbox_inches=”tight”

Bug report

Bug summary

constrained_layout, fixed aspect axes (e.g. from imshow), and savefig(bbox_inches=”tight”) don’t play well together.

Code for reproduction

fig = plt.figure(constrained_layout=True)
fig.add_subplot().imshow(np.random.rand(10, 10))
fig.savefig("/tmp/out.png", bbox_inches="tight")

Actual outcome

out

The axes are cropped, and the aspect=1 is lost (pixels are not square anymore, but slightly elongated).

Expected outcome

Not the above.

Matplotlib version

  • Operating system: linux
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): HEAD
  • Matplotlib backend (print(matplotlib.get_backend())): agg
  • Python version: 39
  • Jupyter version (if applicable):
  • Other libraries:

1 possible answer(s) on “constrained_layout + fixed-aspect axes + bbox_inches=”tight”

  1. I guess one other consideration is this does break %%matplotlib inline, at least when folks are using fixed-aspect axes. I can promise to try and fix over the w/e, but no gauruntees.