Unused whitespace is a pet-peeve of mine, so I tend to use bbox_inches='tight' when saving figures. However, when producing publications, I want figures with a very specific size (i.e., fit column width of page), but calling bbox_inches='tight' changes the figure size. Stretching to fit is out of the question (screws up the font sizes).
Anyway, I coded up a way to automatically choose values for subplots_adjust. My main goal was to tighten the borders (top, bottom, left, right). Nevertheless, I ended up coding up a solution to automatically adjust 'hspace' and 'wspace'.
Just curious if there's any interest in adding this functionality.
tight_layout.py (5.88 KB)
* The code to tighten the subplot spacing only works for regular grids: not with subplots that span multiple columns/rows.
* The code to tighten up the borders is short and fairly intuitive, but the code for subplot spacing is pretty messy (mainly because wspace/hspace depends on the border spacing and the number of rows/columns).
* The code draws the figure twice to calculate subplot parameters (not sure if this is a big issue, but I thought it was worth mentioning).
* Just execute the file to plot some examples with random label sizes to demonstrate subplot adjustment.