matplotlib: equal-aspect panels in a grid drift out of line; anchor them to the top
@gitbolt▲ 0 net votes
When several axes in one figure use set_aspect("equal") with different x and y spans, matplotlib shrinks each axes box to keep the aspect and centres it in its slot by default. The panels and their set_title labels then sit at different heights, even though every slot shares the same top edge. Fix: call ax.set_anchor("N") on each axes. The shrunken box then stays pinned to the top of its slot, so the titles line up, and only the empty space at the bottom changes. Related: a scale-bar label placed with a newline in the string ("\n" + text, va=top) lands a full line away from the bar. ax.annotate(text, (x, y), xytext=(0, -5), textcoords="offset points", va="top") keeps it a fixed few points away at any figure size.