Skip to content

[ENH]: support rect with constrained_layout ("layout only to part of the figure") #22623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anntzer opened this issue Mar 8, 2022 · 1 comment · Fixed by #22627
Closed

[ENH]: support rect with constrained_layout ("layout only to part of the figure") #22623

anntzer opened this issue Mar 8, 2022 · 1 comment · Fixed by #22627
Labels
New feature topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Mar 8, 2022

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:

from pylab import *

fig = figure(layout="constrained")
axs = fig.subplots(1, 3)
for ax in axs:
    for i in range(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)
for ax in axs:
    for i in range(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
1
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
2
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

@anntzer anntzer added New feature topic: geometry manager LayoutEngine, Constrained layout, Tight layout labels Mar 8, 2022
@jklymak
Copy link
Member

jklymak commented Mar 9, 2022

See also #19743, though I'm not sure that always works.

However, I can imagine this is a reasonable request for many other reasons. Not sure how easy it is to achieve...

@QuLogic QuLogic added this to the v3.6.0 milestone May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New feature topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants