Alternatives to tight_layout()

matplotlib, python

Solution

While not the same problem, I worked around issues I was having with `tight_layout()` by adding this to the start of my script instead.

matplotlib.rcParams.update({'figure.autolayout': True})

Problem

Calling `tight_layout()` in matplotlib can lead to: `RunTimeError: "CGContextRef is NULL"`. I have suffered from this error myself with several backends (including `Agg`) in MacOSX and Linux. If I want to achieve the same, or hopefully close enough, effect, without running into these errors, what are my options?

Original source