Repository navigation
Fix Annotation arrow not updating after setting patchA #31438
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
Closed
dikshajangra12918-oss
wants to merge
7
commits into
matplotlib:main
from
dikshajangra12918-oss:patch-2
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5cecde1
Fix Annotation arrow not updating after setting patchA
dikshajangra12918-oss 2f804e7
Preserve user-set patchA in Annotation.update_positions
dikshajangra12918-oss aa4f232
Add test_annotation_patchA_not_overridden function
dikshajangra12918-oss f5f9eec
Fix linting errors in test_text.py
dikshajangra12918-oss 7e78aad
Preserve user-set patchA in update_positions
dikshajangra12918-oss 0bc1e1c
Fix indentation and Whitespace in update_positions
fe152c7
Fix trailig whitespace
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not make sense to me. Please explain what this does and why it is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sir,
The issue is that update_positions() runs on every draw and always overwrites patchA with a recomputed value - so if a user manually calls set_patchA(), their value gets silently lost on the next draw.
The fix: I store the last patchA I set internally in _internal_patchA. Before overwriting, I check if arrow_patch.patchA is still the same object. If yes then user hasn't touched it, safe to update. If no then user set it manually, so I skip the override.
getattr(self, '_internal_patchA', None) handles the first draw gracefully- defaults to None so the initial set always works fine.
Added test_annotation_patchA_not_overridden to verify this- it manually sets a custom patchA, triggers draw_without_rendering(), and asserts the value is preserved after the draw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I would question if manually setting patchA is a valid use case.
Annotationis primarily a Text object with the ability to refer to a coordinate position xy. It can optionally draw an arrow from its xytext postion to xy. That arrow (starting at xytext) may be partially covered by the text and the text bounding box serves as patchA. I would say that the patchA is owned by theAnnotationand I am not clear that a user-override is reasonable.It may be that the use case should instead be solved via
ConnectionPatch, see #26440. @story645 do you agree?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sir,
The original use case (from @Phlya) is in the adjustText library, where ax.annotate() is used instead of FancyArrowPatch directly — and the user needs to modify arrow_patch.patchA afterward to avoid arrows passing through text objects.
If ConnectionPatch is the recommended approach for this use case, I'm happy to close this PR. But if set_patchA() is documented as a valid method on arrow_patch, silently ignoring it seems like a bug worth fixing.
Happy to follow your guidance on the right direction!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unclear why the original user wants to overwrite the patchA - #28316 (comment).
Let's first try to find out what the actual problem is that the user wants to solve.