Discsusion/Feature request: subplot-managed axis labels

When drawing “small multiples” — a grid of subplots where each uses the same x and y variables — it can be cleaner to use a pair of labels that collectively annotate the x and y axes of all plots, ideally centered on the horizontal and vertical span of the collection of axes.

Here’s what I mean:

image

I don’t believe matplotlib has a robust and generic way to create these labels. In the above example, I set the axes-level labels for the middle row/column, which only works when ncol and nrow are odd. It could be possible to get the SubplotSpec bbox and work out where to draw fig.text labels, but I don’t think these will update properly with tight_layout/constrained_layout.

Would it be possible for the matplotlib.gridspec.SubplotSpec object to define {get,set}_{x,y}label? How hard would this be to implement? Is there interest?

PS I guess people might reasonably expect subplot-managed titles too. And legends? I can see how this request might get out of hand. Then again, all of these features would be useful if there are abstractions that can make them not too burdensome.

Thats a reasonable request. See https://github.com/matplotlib/matplotlib/issues/11147 for previous discussion, and https://github.com/matplotlib/matplotlib/pull/13072 for the same thing for legends. We already have suptitle, but it is on a figure basis.

I agree that this should go at the gridspec level, and then they can be nested.

I think this would be easy to implement with constrained_layout, though gridspec-level decorators are kind of a sticking point right now. suptitle is special cased, and its relatively trivial in constrained_layout.