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 cl subgridspec#22144

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
timhoffm merged 3 commits intomatplotlib:mainfromjklymak:fix-cl-subgridspec
Jan 9, 2022
Merged

Conversation

jklymak
Copy link
Member

PR Summary

Closes#22143

If subgridspecs were identical, then their strings were identical, and the dictionary we had for the layoutgrids was being addressed with the same key twice. Changed the key to a unique repr for the subgridspec.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

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

@jklymakjklymak added this to thev3.5.2 milestoneJan 7, 2022
@jklymakjklymak added topic: geometry managerLayoutEngine, Constrained layout, Tight layout Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labelsJan 7, 2022
Comment on lines 206 to 207
# get a unique representation:
rep = object.__repr__(gs) + 'top'
Copy link
Member

Choose a reason for hiding this comment

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

Can you not simply use the memory address of the object:id(gs)?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'm not sure.gs is used as a key as well, so I wanted to differentiate.

Copy link
Member

Choose a reason for hiding this comment

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

If the use of the key is to 1) be unique to each gridspec and 2) does not need to be human readable, I would go with usingid(gs). Either way, I think the keys should be of a similar type, so it would be good to modify the if block above this to use eitherid(gs) orobject.__repr__(gs).

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

The whole set of codeusually just useslayoutgrid[obj] whereobj is the actual object, be it a gridspec, figure etc. Wecould make them all belayoutgrid[id(obj)] but that would introduce a lot of extra typing.

Here, this is just a dummy shell so that the hierarchy of subgridspecs is the same as other objects, in that they all have a parent that can hold suptitles, etc. There is no associated object on the figure corresponding to this, so I just am using a dummy here. The problem with the original code is that the dummy wasn't unique!

We can certainly useid, but that loses any hint of what the object was in the key.object.__repr__ keeps the type infoand theid. i.e. for this case we get a string"<matplotlib.gridspec.GridSpecFromSubplotSpec object at 0x17b686790>top"

Copy link
Member

Choose a reason for hiding this comment

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

Another thought - since__repr__ is typically a string that can be passed toeval() to create an identical copy of the object, it isn't always unique, e.g.:

>>> 'abc'.__repr__()"'abc'"

So I would still say if you want to guarentee uniqueness, useid() in case we changeGridSpecFromSubplotSpec.__repr__ to a non-instance-unique string in the future.

Copy link
Member

Choose a reason for hiding this comment

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

When we use the base classobject.__repr__, this should always result inf"<{gs.__class__.__name__} object at {id(gs)}>". Uniqueness should be guaranteed. But maybe just just the explicit formatting instead of the slightly unusualobject.__repr__.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could perhaps uselayoutgrids[(gs, "top")] (which can even be spelledlayoutgrid[gs, "top"]).

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Ah OK, thats reasonable. It really never gets referenced except by the child viachild.parent, so it just needs to be identifiable for debug purposes.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Newest commit just uses the tuple...

@timhoffmtimhoffm merged commitb3f61d1 intomatplotlib:mainJan 9, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestJan 9, 2022
timhoffm added a commit that referenced this pull requestJan 9, 2022
…144-on-v3.5.xBackport PR#22144 on branch v3.5.x (Fix cl subgridspec)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@anntzeranntzeranntzer left review comments

@timhoffmtimhoffmtimhoffm approved these changes

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Labels
Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.topic: geometry managerLayoutEngine, Constrained layout, Tight layout
Projects
None yet
Milestone
v3.5.2
Development

Successfully merging this pull request may close these issues.

[Bug]:constrained_layout merging similar subgrids
4 participants
@jklymak@anntzer@timhoffm@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp