⚡ Sangsakala Proxy 🏠 Home
Skip to content

ENH: Added sharex/sharey string support to subplot_mosaic - #32437

Open
nillohitroy wants to merge 8 commits into
matplotlib:mainfrom
nillohitroy:subplot_mosaic-share-issue-18305
Open

nillohitroy wants to merge 8 commits into
matplotlib:mainfrom
nillohitroy:subplot_mosaic-share-issue-18305

Conversation

@nillohitroy

@nillohitroy nillohitroy commented Oct 4, 2026 •

Copy link
Copy Markdown

PR summary

This PR implements string arguments ('all', 'row', 'col') and boolean True/False for sharex and sharey in subplot_mosaic() for #18305 .

To handle complex and nested layouts, the axes are grouped based on their specific GridSpec and exact rowspan/colspan coordinates. Axes only share a row or column if their spans are identical.
For example, consider a layout where C and D span both rows:

ABCD
EFCD

If sharey='row' is passed, the code forms three isolated sharing groups based on their vertical spans:

  • [A, B] (Row 0)
  • [E, F] (Row 1)
  • [C, D] (Spanning Rows 0 and 1)

Once the groups are isolated, the logic designates the first axis in each list as the parent and calls standard .sharex(parent) or .sharey(parent) on the remaining children in that specific group.

Important Note: Relying on Matplotlib's global ax._label_outer_xaxis() or ax._label_outer_yaxis() inadvertently hid tick labels for inner subplots if they formed their own isolated sharing group. For this very reason, I implemented a custom logic which calculates label visibility dynamically per group. For example, in an X-axis sharing group, it calculates the physical bottom edge by finding the max() of rowspan.stop across just the group's members. It then loops through that group and applies ax.tick_params(labelbottom=False) to any axis sitting above that localized bottom edge.

AI Disclosure

I have used Generative AI to understand the codebase (specifically the code for the issue), setting up of the environment (installing packages and dependencies required), the intent of the issue and to get to the center of the problem. It is also important to mention that AI was used to understand the requirements of the maintainers and how #32239 failed and what to avoid while coding.

Verification

I have tested the code for a local matplotlib development build, running it on my system and creating a sample plot for a sample data. Also, I have written some test cases for the same by trying to incorporate as many test cases as possible (5), all of which successfully passed.

I would be happy for any feedback regarding any portion of the code!!

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [/] Plotting related features are demonstrated in an example
  • [/ ] New features and API changes have release notes
  • [/ ] Documentation complies with general and docstring guidelines

Copilot AI balanced review requested due to automatic review settings October 4, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@nillohitroy

Copy link
Copy Markdown
Author

Dear Maintainers,
I have seen how diligently you guys work and how mentally constraining reviewing each line of the code is. Though this issue is a 'good first issue' and not as complex (and may be not as important) as compared to the other bug fixes that the contributors are providing. I would be obliged if you could review my code and give me necessary feedback to improve it as much as possible.

@iccir

iccir commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Assuming that I'm talking to an actual human: this PR is currently failing to pass the Linting and MyPy Stubtest checks. The AppVeyor build failure is somewhat expected as AppVeyor has been flaky recently.

Generally, you will want to make sure that all checks pass on any PR that you open to a repository. You need to get at least Linting and the stub test to pass first.

@nillohitroy

Copy link
Copy Markdown
Author

Assuming that I'm talking to an actual human: this PR is currently failing to pass the Linting and MyPy Stubtest checks. The AppVeyor build failure is somewhat expected as AppVeyor has been flaky recently.

Generally, you will want to make sure that all checks pass on any PR that you open to a repository. You need to get at least Linting and the stub test to pass first.

Thank you sir.. on it..

@github-actions github-actions Bot added topic: geometry manager LayoutEngine, Constrained layout, Tight layout topic: rcparams Documentation: devdocs files in doc/devel labels Oct 7, 2026
@nillohitroy

Copy link
Copy Markdown
Author

Hi @iccir
I think I have screwed up in some way. Thing is, I have done a pull request and merged the code, so instead of just 1 commit, there is 11 commits and also some failed tests (of other developers). I have checked my tests (linting and all) and everything is successful. My question is: will everything work or do I have to open a new pull request?
Sorry for any trouble I have caused.

@rcomer

rcomer commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

I think a rebase should sort that out. Assuming you have set the upstream remote as described here, try this:

Make a backup branch in case something else goes wrong

git branch my-backup-branch 

Rebase on the upstream branch

git fetch upstream
git rebase upstream/main

git push will then fail, but you can

git push --force-with-lease

@iccir

iccir commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Hey, it happens - git can be tricky :)

It looks like you made two commits:
c278400
a14df4f

I'd do something like the following:

git diff \
    c278400dee9b6758ce74f0eab9b5cbc085b595ee^ \
    a14df4f320b0b13ebdf7fc34cf4d356e5f0f67ea > \
    /someplace/safe/changes.patch

Then I'd follow @rcomer's instructions above. You can always reapply the patch with:

git apply /someplace/safe/changes.patch

@nillohitroy
nillohitroy force-pushed the subplot_mosaic-share-issue-18305 branch from 4f25789 to 1416ea3 Compare October 8, 2026 01:04
@github-actions github-actions Bot removed topic: geometry manager LayoutEngine, Constrained layout, Tight layout topic: rcparams Documentation: devdocs files in doc/devel labels Oct 8, 2026
@nillohitroy

nillohitroy commented Oct 8, 2026 •

Copy link
Copy Markdown
Author

Hi @rcomer @iccir
Thank you for being so kind and helpful. I have solved the issue with the merge request.
However, as shown, there is a failing test with Mac OS and I don't have a MAC so I really don't know what the issue is.

@iccir

iccir commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

If you get a test failure that you don't understand, there are several possibilities:

  1. The test failure is caused by a specific version of Python. For example, we could see Python 3.12 failing across several different operating systems.
  2. The test failure is caused by a specific platform. We could see all macOS builders fail, for example.
  3. A test failure on a specific version of Python and a specific platform. You would see a single test failure, as in this case.

More commonly, however, #3 can indicate that something is wrong with the Continuous Integration (CI) system.

You can often look at other pull requests to see if they are having similar issues. Python 3.12 on macOS 15 has been failing all day - here's another example with the same error.

So, it's probably not an error in your code!

@nillohitroy

Copy link
Copy Markdown
Author

If you get a test failure that you don't understand, there are several possibilities:

  1. The test failure is caused by a specific version of Python. For example, we could see Python 3.12 failing across several different operating systems.
  2. The test failure is caused by a specific platform. We could see all macOS builders fail, for example.
  3. A test failure on a specific version of Python and a specific platform. You would see a single test failure, as in this case.

More commonly, however, #3 can indicate that something is wrong with the Continuous Integration (CI) system.

You can often look at other pull requests to see if they are having similar issues. Python 3.12 on macOS 15 has been failing all day - here's another example with the same error.

So, it's probably not an error in your code!

I also have the same view as you. It is showing that the test is failing only in macos-15 (macos26 is running successfully). Also, I have tested the code locally as well, so I'm pretty confident about it. My request is if you could review my code so as to ensure if there are other major issues or this code can be merged to the repo..

@nillohitroy

Copy link
Copy Markdown
Author

Hi @rcomer
Sorry to disturb you like this. But is it possible for you to review my code?

@nillohitroy
nillohitroy requested a balanced review from Copilot October 12, 2026 15:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Fix nested-layout label visibility by comparing physical positions and update the public documentation.

3 open findings

🧠 Review effort: Lite

Comment thread lib/matplotlib/figure.py Resolved
Comment thread lib/matplotlib/figure.py Resolved
Comment thread lib/matplotlib/pyplot.py Resolved
@nillohitroy

Copy link
Copy Markdown
Author

@timhoffm
I have made the changes as mentioned in the review. Please check if the changes made are correct and again thank you for your valuable feedback.

@nillohitroy

Copy link
Copy Markdown
Author

Hi @timhoffm
Could you please check if there are any issues? If not, then could you please approve my PR?

Comment thread lib/matplotlib/tests/test_figure.py Resolved
Comment thread lib/matplotlib/tests/test_figure.py Resolved
Comment thread lib/matplotlib/tests/test_figure.py Resolved
Comment thread lib/matplotlib/figure.py Resolved
Comment thread lib/matplotlib/figure.py Resolved
Comment thread lib/matplotlib/pyplot.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Moderate issues remain with outer-label behavior and the Figure API documentation/release notes.

2 open issues
2 resolved since last review

Review effort: Lite

Comment thread lib/matplotlib/figure.py Resolved
Comment thread lib/matplotlib/tests/test_figure.py Resolved
Comment thread lib/matplotlib/tests/test_figure.py Resolved
Comment thread lib/matplotlib/figure.py Resolved
Comment thread lib/matplotlib/tests/test_figure.py Resolved
Comment thread lib/matplotlib/tests/test_figure.py Resolved
Comment thread lib/matplotlib/tests/test_figure.py Resolved
@nillohitroy

Copy link
Copy Markdown
Author

Hi @timhoffm
Could you please review the code again? As you mentioned instead of frozensets, I used sets but inside a list (since a set is unhashable and using it inside another set will give an error). Do mention if there are any more improvements needed..

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test structure is good now.

The copilot comment is a valid point. What do we do about it?
#32437 (comment)

@nillohitroy

Copy link
Copy Markdown
Author

The test structure is good now.

The copilot comment is a valid point. What do we do about it? #32437 (comment)

The issue is that my fix is quite incomplete in the sense that if instead of standard notations, the user uses scientific notations (The tick_params call leaves the OffsetBox text fully visible on inner axes). Also, since we left aside labeltop and labelright visibility, it will popup as well.

So, it's your call Captain.

@timhoffm

timhoffm commented Nov 2, 2026

Copy link
Copy Markdown
Member

We should not ship an incomplete implementation. We actually have the semantics sort of available via _label_outer_xaxis() / _label_outer_yaxis().

Please check: That functionality is coded for regular grids and is not directly suitable for mosaic. Can one split this into (a) detecting whether an axis is "outer" and (b) applying the needed config to the axis. (a) is different for grids and mosaic; (b) may be reusable for both cases.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A moderate regression causes shared polar mosaics to hide inner theta tick labels by bypassing the non-rectangular-axis guard, and the FigureBase API documentation also remains stale.

1 open issue
3 resolved since last review

Review effort: Lite

Comment thread lib/matplotlib/figure.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The public description should explicitly clarify that matching spans are only shared when they belong to the same GridSpec, especially for nested mosaics.

1 open issue
1 resolved since last review

Review effort: Lite

Comment thread lib/matplotlib/figure.py
Comment on lines +2040 to +2044
behave as for `subplots`. If 'row', Axes that occupy the exact same row span
(the same vertical space in the grid) will share an x-axis (or y-axis).
If 'col', Axes that occupy the exact same column span (the same horizontal
space in the grid) will share an x-axis (or y-axis). If False or 'none',
each subplot's x- or y-axis will be independent.
@nillohitroy

Copy link
Copy Markdown
Author

Hi @timhoffm
I have added changes you recommended. At the same time, I did a lite review and another issue came up with polar coordinates. I have fixed that as well.
So if you can review this PR?

@nillohitroy

Copy link
Copy Markdown
Author

Thank you @timhoffm
Actually this is my first PR and I don't know much about the workflows.. so now do I have to wait for this PR to be merged automatically? Hope I am not rude with this question.

@lucaznch

lucaznch commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Hi @nillohitroy. Code changes require two approving reviews so you'll need one more approval before this PR can be merged (which is handled by a maintainer). Your contribution is appreciated, but keep in mind that review capacity can sometimes be limited.

@nillohitroy

nillohitroy commented Nov 3, 2026 •

Copy link
Copy Markdown
Author

Hi @lucaznch
Thank you for taking out your precious time and answering my question. I appreciate the work, maintainers are doing and I can understand how much time and energy it requires to review all these code. So I can patiently wait for it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants