Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Compressed layout moves suptitle #28734

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

Merged
merged 1 commit into from
Aug 21, 2024
Merged

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Aug 16, 2024

PR summary

Closes #27866. I found myself wanting this today. The code from the issue now produces

test

I am at a loss how to provide a deprecation path for this.

PR checklist

@rcomer rcomer added topic: geometry manager LayoutEngine, Constrained layout, Tight layout API: changes labels Aug 16, 2024
@rcomer rcomer added this to the v3.10.0 milestone Aug 16, 2024
@rcomer rcomer force-pushed the compressed-suptitle branch from 6cd82cb to 68903da Compare August 16, 2024 19:11
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't imagine anyone will complain if this doesn't get a deprecation.

@rcomer
Copy link
Member Author

rcomer commented Aug 19, 2024

I belatedly found the plot_children function so can now visualise that I'm using the blue rectangle to position the title.

test

suptitle.get_in_layout() and suptitle._autopos):
x, _ = suptitle.get_position()
suptitle.set_position(
(x, layoutgrids[fig].get_inner_bbox().y1 + 0.02))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does 0.02 come from? Does it work well with different font sizes?

Copy link
Member Author

@rcomer rcomer Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.02 is the default space between the top of this title and the top of the figure without constrained layout, so I chose it to be consistent with that.

This comment was marked as outdated.

Copy link
Member Author

@rcomer rcomer Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though thinking about it, it's probably better to do something consistent with the make_margin_suptitles function which would define the spacing if you are using normal constrained layout or if compressed layout is compressing things horizontally. That ultimately uses the configurable h_pad.

Copy link
Member Author

@rcomer rcomer Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what happens with my current (0.02) implementation if compressed layout is not moving axes in the vertical and I do not use bbox_inches='tight'. I will change it to use h_pad.

test_x-large(1)

Copy link
Member Author

@rcomer rcomer Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the update, here is what I get with figsize=(5, 5) and no bbox_inches='tight'. This looks identical to what I get with main:
test_x-large

Here is what I get with figsize=(4, 10) and saving with bbox_inches='tight', pad_inches='layout':
test_x-large(1)

@rcomer rcomer force-pushed the compressed-suptitle branch from 68903da to 146ba53 Compare August 20, 2024 12:25
@rcomer rcomer requested a review from jklymak August 20, 2024 12:39
@rcomer
Copy link
Member Author

rcomer commented Aug 20, 2024

Docs are broken on main.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks good to me!

@timhoffm timhoffm merged commit 85d7295 into matplotlib:main Aug 21, 2024
39 of 43 checks passed
@rcomer rcomer deleted the compressed-suptitle branch August 22, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: changes topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Adding suptitle in compressed layout causes weird spacing
4 participants