Skip to content

Do not pass gridspec_kw to inner layouts in subplot_mosaic #24189

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 16 commits into from
Oct 21, 2022

Conversation

joshbarrass
Copy link
Contributor

@joshbarrass joshbarrass commented Oct 16, 2022

PR Summary

Constructs a new gridspec_kw dictionary with the "width_ratios" and "height_ratios" removed, which is passed to the inner layouts instead of the original. This prevents an error from occurring when one of the inner layouts is not compatible with one of the specified ratios.

The gridspec_kw arg when constructing a nested layout with subplot_mosaic is no longer passed to any of the inner layouts. These args are generally not applicable to any of the inner layouts, and can cause exceptions to be raised in some cases (for example, the "width_ratios" and "height_ratios" cause an error when one of the nested layouts is not compatible with one of these ratios). More complex layouts should be constructed directly using .subfigure and .subplots.

Fixes #24099
Resubmission of #24188 with a more appropriate branch name.

Currently has one warning when building the docs, which will be fixed by #24190

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@joshbarrass joshbarrass changed the title Do not pass width_ratios or height_ratios to inner layouts in subplot_mosaic Do not pass gridspec_kw to inner layouts in subplot_mosaic Oct 17, 2022
@joshbarrass joshbarrass requested a review from jklymak October 19, 2022 12:57
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.

Just some sorting suggestions that you can argue for or against.

@jklymak
Copy link
Member

jklymak commented Oct 19, 2022

Sorry

home/circleci/project/lib/matplotlib/figure.py:docstring of matplotlib.figure.Figure:49: WARNING: py:obj reference target not found: subfigure
/home/circleci/project/lib/matplotlib/figure.py:docstring of matplotlib.figure.Figure:49: WARNING: py:obj reference target not found: subfigure
/home/circleci/project/lib/matplotlib/figure.py:docstring of matplotlib.figure.Figure:49: WARNING: py:obj reference target not found: subfigure
/home/circleci/project/doc/api/next_api_changes/behavior/24189-JB.rst:4: WARNING: py:obj reference target not found: Figure.subfigure

Sorry, should have been .Figure.subfigures I think...

@joshbarrass
Copy link
Contributor Author

@jklymak I've updated those lines to .Figure.subfigures now. Fingers crossed everything works now (:

@tacaswell tacaswell added this to the v3.7.0 milestone Oct 19, 2022
@tacaswell
Copy link
Member

Are there any uses of passing things through that will now be broken?

I do not think this in the right fix as the issue here is that the height and width ratios are being passed through not generic gridspec kwargs. I think instead we should not merge the two ratio into the user supplied dictionary and only use those at the top level and let the user supplied gridspec_kw dictionary still flow all the way through as there are other keywords that you would want to thread through that do not depend on exactly matching the shape of the layout.

More complex layouts should be constructed directly using .subfigure and .subplots.

I do not agree with this and this were a case, we should rip out all of the recursive logic in subplot_mosaic.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

I think this is making too big of a change and we can instead not pass through the independently specified ratios.

@jklymak
Copy link
Member

jklymak commented Oct 20, 2022

as there are other keywords that you would want to thread through that do not depend on exactly matching the shape of the layout.

That was discussed above - what is left are w/hspace, left/top etc. Is there really a case where a user has set these, and also expects the same values to be passed down to lower levels? These are all passed in figure-relative units, so they will all halve in physical size at lower levels. It would be a pretty fortuitous layout that wanted this.

More complex layouts should be constructed directly using .subfigure and .subplots.

I do not agree with this and this were a case, we should rip out all of the recursive logic in subplot_mosaic.

Almost all the subplot mosaic calls I've seen are made with layout='constrained' which ignores w/hspace, left/top etc. anyhow. So unless we want to allow the user to have a nested set of gridspec_kws I think the current proposal is the cleanest.

BTW, the above should read: More complex layouts should be constructed directly using .subfigure and .subplots or .subplot_mosaic. You can still use subplot_mosaic on the subfigure.

@tacaswell
Copy link
Member

That was discussed above - what is left are w/hspace, left/top

Sorry, I did not unfold and read the in-line discussion and was just reacting to the current state of the PR. I now see that there was extensive discussion in them.

I find the argument that none of these arguments make sense recursively (and passing them through at all was a mistake (that is my fault)). I think this should be made clearer in the deprecation note as now it reads (to me) like "This works most of the time but we are going to break it because it does not work in some corner cases".

I'm of bit of a mind to deprecate gridspec_kw all together I think that is worse (it breaks the rhyming with fig.subplots).


@joshbarrass Sorry for over-reacting a bit on your first PR, I assure you it is not personal.

@tacaswell tacaswell dismissed their stale review October 20, 2022 16:58

I did not read enough context and over-reacted. Would still like the deprecation message to be a worded a bit more strongly, but will not block over that.

@joshbarrass
Copy link
Contributor Author

No problem @tacaswell. I can totally understand where you are coming from, particularly as I originally drafted this PR that way (:

I've updated the message to reflect the discussion, that the behaviour is being changed because it is rarely appropriate for these arguments to be passed to the inner layouts. Does this make the reasoning for the change clearer in everyone's opinions?

Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@tacaswell tacaswell merged commit 3a5c6dc into matplotlib:main Oct 21, 2022
@tacaswell
Copy link
Member

I squashed merged this to keep the history a bit cleaner.


Thank you for you work @joshbarrass and congratulations on your first merged Matplotlib PR 🎉 Hopefully we will hear from you again!

melissawm pushed a commit to melissawm/matplotlib that referenced this pull request Dec 19, 2022
…b#24189)

* Do not pass width/height ratios to nested layouts

Co-authored-by: Jody Klymak <jklymak@gmail.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Error using width_ratios with nested mosaic in subplot_mosaic()
4 participants