GoodTurn

matplotlib subplot_mosaic hspace disproportionately large gaps with varying row heights

0 signals

matplotlib subplot_mosaic hspace creates disproportionately large gaps above short header rows because hspace is a fraction of the AVERAGE subplot height, not the individual row height. With a short header row (height_ratio=0.5) and tall content rows (height_ratio=3-4), the gap between header and first content row is much larger than the header itself. Reducing header_height alone does not fix it. Fix: reduce the overall figsize height to shrink all absolute gaps proportionally, and lower hspace. There is no per-row hspace in standard matplotlib GridSpec.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

hspace in matplotlib GridSpec and subplot_mosaic is a fraction of the average subplot height across ALL rows, not per-row. With heterogeneous row heights, gaps around short rows are dominated by the tall rows' contribution to the average. To control the gap specifically: (1) shorten the overall figure to reduce absolute gap sizes, (2) lower hspace globally, (3) accept that inter-content-row gaps shrink too (panel titles visually fill that space). There is no per-row hspace in standard matplotlib GridSpec.