Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix colorbar alignment with suptitle in compressed layout mode#30766

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jklymak merged 7 commits intomatplotlib:mainfrommiriamsimone:main
Nov 27, 2025

Conversation

@miriamsimone
Copy link
Contributor

PR summary

closes#30472

This PR fixes a colorbar alignment issue when using compressed layout mode
with suptitle. In compressed layout, whenapply_aspect() is called on
axes (triggered by the presence of a suptitle), colorbars were not
properly aligning with their parent axes because they were being sized
based on the pre-aspect-adjustment dimensions.

Why is this change necessary?
When usinglayout='compressed' with a suptitle, the axes undergo aspect
ratio adjustments that change their visual height. Colorbars attached to
these axes were not accounting for this adjustment, resulting in
misaligned colorbars that didn't match their parent axes' vertical extent.

What problem does it solve?
Colorbars now properly align with their parent axes in compressed layout
mode, maintaining the same height and vertical position even when the
parent axes have been resized by aspect ratio constraints.

What is the reasoning for this implementation?
The fix passes acompress flag through the repositioning chain and, when
in compressed mode with single-parent vertical colorbars, uses the actual
post-aspect-adjustment position of the parent axis to calculate the
colorbar's bounding box. This ensures the colorbar dimensions match the
visually rendered parent axes rather than the pre-adjustment layout grid
dimensions.

Example:

importnumpyasnpimportmatplotlib.pyplotaspltarr=np.arange(100).reshape((10,10))fig,axs=plt.subplots(ncols=2,figsize=(4,2),layout='compressed')axs[0].imshow(arr)axs[1].imshow(arr)plt.colorbar(axs[0].images[0],ax=axs[0])plt.colorbar(axs[1].images[0],ax=axs[1])fig.suptitle('Title')plt.show()

PR checklist

  • "closes #0000" is in the body of the PR description to link the related
    issue
  • new and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New Features and API Changes are noted with a directive and
    release note
  • [N/A] Documentation complies with general and docstring guidelines

@github-actionsgithub-actionsbot added the topic: geometry managerLayoutEngine, Constrained layout, Tight layout labelNov 19, 2025
@miriamsimone
Copy link
ContributorAuthor

closing and reopening to rerun tests

@miriamsimone
Copy link
ContributorAuthor

maybe someone can help me with getting the tests to pass?

@timhoffm
Copy link
Member

You can ignore the failing tests here. They are known to be flaky.

@timhoffm
Copy link
Member

Thanks for the contribution.

The same effect can happen for horizontal bars:

arr=np.arange(100).reshape((10,10))fig,axs=plt.subplots(nrows=2,figsize=(3,4),layout='compressed')im0=axs[0].imshow(arr)im1=axs[1].imshow(arr)cb0=plt.colorbar(im0,ax=axs[0],orientation='horizontal')cb1=plt.colorbar(im1,ax=axs[1],orientation='horizontal')fig.supylabel('Title')
image

Could you please generalize to include this as well?

@miriamsimone
Copy link
ContributorAuthor

generalized to horizontal
Screenshot 2025-11-21 at 5 56 16 PM

@jklymak
Copy link
Member

This looks good, but please fix the linting errors!

@miriamsimone
Copy link
ContributorAuthor

fixed linting errors

@image_comparison(['test_compressed_supylabel_colorbar.png'],style='mpl20')
deftest_compressed_supylabel_colorbar():
"""
Test that horizontal colorbars align with axes
Copy link
Member

Choose a reason for hiding this comment

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

Linting is still mad about the trailing white space here.

@jklymakjklymak merged commitdcff41f intomatplotlib:mainNov 27, 2025
36 of 39 checks passed
@jklymak
Copy link
Member

Thanks for sorting this out@miriamsimone !

@QuLogicQuLogic added this to thev3.11.0 milestoneNov 28, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jklymakjklymakjklymak approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees

No one assigned

Labels

topic: geometry managerLayoutEngine, Constrained layout, Tight layout

Projects

None yet

Milestone

v3.11.0

Development

Successfully merging this pull request may close these issues.

[Bug]: layout=compressed conflict with suptitle

4 participants

@miriamsimone@timhoffm@jklymak@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp