Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Problem
tight_layout supports a rect option ("layout axes so that they fit within this rect instead of filling the entire figure"). It could be nice if constrained_layout also supported that.
As an example use case, requested by@jklymak on gitter:
frompylabimport*fig=figure(layout="constrained")axs=fig.subplots(1,3)foraxinaxs:foriinrange(3):ax.plot(rand(3),rand(3),label=f"dataset{i}")axs[1].legend(ncol=3,loc="lower center",bbox_to_anchor=(0.5,1.0))fig=figure(layout="constrained")axs=fig.subplots(1,3)foraxinaxs:foriinrange(3):ax.plot(rand(3),rand(3),label=f"dataset{i}")fig.legend(handles=axs[0].lines,ncol=3,loc="upper center")show()
This draws e.g. three different coordinates of three datasets, and tries to have a single one-line legend at the center top.
The first try gives
i.e. it would work if set_in_layout could be used to take the legend's y extent, but not its x extent (now that I think of it, that may be the better solution).
The second try gives
which is where I think a rect option would work to avoid the axes overlapping the legend (you'd have to tweak the value a bit manually, though, to specify the upper bound of the rect). (Perhaps not the nicest solution, but "could work when you just want to get a plot done".)
Proposed solution
No response