Skip to content

Fix behaviour of Figure.clear() for SubplotParams #27183

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 43 commits into from
Apr 23, 2025

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Oct 24, 2023

PR summary

  • Update Figure.clear() to reset the properties of Figure.subplotpars.
  • Add representation method for matplotlib.gridspec.SubplotParams
  • Add rc_default parameter to the SubplotParams.update

Fixes #11059. This PR is a continuation of #11086 by @fredrik-1

PR checklist

@ksunden ksunden marked this pull request as draft October 24, 2023 20:55
@eendebakpt eendebakpt changed the title Draft: Fix behaviour of Figure.clear() for SubplotParams Fix behaviour of Figure.clear() for SubplotParams Oct 25, 2023
@eendebakpt eendebakpt marked this pull request as ready for review October 25, 2023 09:27
@eendebakpt
Copy link
Contributor Author

@jklymak Would you be able to review this pr? Thanks

@tacaswell
Copy link
Member

Why add an additional flag to update rather than extracting the rcparam values and passing them in clear (where we have to add a call to update anyway)?

I am not against the current implementation, but am curious why a more minimal approach would not work?

@eendebakpt
Copy link
Contributor Author

Why add an additional flag to update rather than extracting the rcparam values and passing them in clear (where we have to add a call to update anyway)?

I am not against the current implementation, but am curious why a more minimal approach would not work?

@tacaswell This is a continuation of #11086 and I followed the implementation there.

Looking at the code right now: the new flag is used both in clear() and subplots_adjust(...). If we would only modify the clear(), then I fully agree we could do without the flag. If we do add a parameter to subplots_adjust, then the flag in update avoids a bit of duplicated code in clear and subplots_adjust.

I am fine with leaving the PR as is, or removing the flag in both update and subplots_adjust, or removing the flag in update while generating the new parameters in both clear and subplots_adjust.

@github-actions github-actions bot added topic: geometry manager LayoutEngine, Constrained layout, Tight layout topic: pyplot API topic: figures and subfigures Documentation: user guide files in galleries/users_explain or doc/users and removed status: needs rebase labels Jan 16, 2024
@eendebakpt
Copy link
Contributor Author

@tacaswell Gentle ping

@eendebakpt eendebakpt requested a review from ksunden January 24, 2024 10:36
@github-actions github-actions bot removed Documentation: user guide files in galleries/users_explain or doc/users status: needs rebase labels Feb 27, 2024
The height of the padding between subplots,
as a fraction of the average Axes height.
"""
for key in ["left", "bottom", "right", "top", "wspace", "hspace"]:
setattr(self, key, mpl.rcParams[f"figure.subplot.{key}"])
self.update(left, bottom, right, top, wspace, hspace)

def _repr_pretty_(self, p: Any, cycle: bool) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Why not simply define __repr__?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

__repr__ ends up at many places (logging, inside other repr of containers) and not everybody likes these kind of changes. The _repr_pretty_ is mainly used in interactive environments (spyder, jypyter noteobook, etc.) and visible to humans.

I do not think this change belongs in this PR though, so I removed it. Let me know if you want to to open a separate PR for this.

Copy link
Member

Choose a reason for hiding this comment

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

It's rare that we/users ever access this, so I don't really care. But I think if we do this, we can afford to do __repr__. We don't have precedence for _repr_pretty_ in the code base. Take or leave a separate PR.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Only minor changes left.

eendebakpt and others added 2 commits April 22, 2025 10:42
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
eendebakpt and others added 3 commits April 22, 2025 20:22
Co-authored-by: Jody Klymak <jklymak@gmail.com>
Co-authored-by: Jody Klymak <jklymak@gmail.com>
Co-authored-by: Jody Klymak <jklymak@gmail.com>
@jklymak
Copy link
Member

jklymak commented Apr 22, 2025

You have a stray end of file issue that fails CI.

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.

Small suggestion to the what's new (at the very least the line was too long).

If someone merges this, it should be squash-merged.

Co-authored-by: Jody Klymak <jklymak@gmail.com>
@QuLogic
Copy link
Member

QuLogic commented Apr 23, 2025

pre-commit.ci autofix

@QuLogic QuLogic merged commit 00d5cb6 into matplotlib:main Apr 23, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: figures and subfigures topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

figure.clf() and subplots_adjust
7 participants