Skip to content

Fix Annotation arrow not updating after setting patchA#31438

Draft
dikshajangra12918-oss wants to merge 5 commits intomatplotlib:mainfrom
dikshajangra12918-oss:patch-2
Draft

Fix Annotation arrow not updating after setting patchA#31438
dikshajangra12918-oss wants to merge 5 commits intomatplotlib:mainfrom
dikshajangra12918-oss:patch-2

Conversation

@dikshajangra12918-oss
Copy link
Copy Markdown

PR summary

Why is this change necessary?

Setting patchA on Annotation.arrow_patch currently has no visible effect because the arrow position is not recomputed after updating patchA.

What problem does it solve?

This change ensures that when patchA is modified, the annotation is marked as stale. This triggers a recomputation of the arrow position during rendering, fixing the issue where the arrow does not align or clip correctly with the associated text.

What is the reasoning for this implementation?

The arrow position is initially computed correctly, but subsequent updates to patchA are not reflected visually. By marking the annotation as stale when patchA changes, we ensure that the rendering pipeline updates the arrow position accordingly.

AI Disclosure

AI assistance was used in a manner for understanding parts of the codebase and validating the approach. The implementation and reasoning were completed and verified independently.

Setting patchA on Annotation.arrow_patch has no visible effect because the arrow position is not recomputed.

This change ensures that the annotation is marked as stale when patchA changes, triggering proper recomputation during rendering.
Copy link
Copy Markdown
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

I don't really understand how this is a fix. update_positions is called from draw, which means the artist is already stale and you're triggering a second draw now by marking it stale again.

Also, is this fixing some existing bug? Please add a test to show what you are actually fixing.

@timhoffm timhoffm linked an issue Apr 3, 2026 that may be closed by this pull request
Add logic to prevent overriding user-set patchA in update_positions. Fixes issues matplotlib#28316.
Add test to verify that manually set patchA on  annotation arrow is preserved after draw.
@dikshajangra12918-oss
Copy link
Copy Markdown
Author

Thankyou for the review!
I rethought the approach after your comment. Instead of marking the annotation stale, I now track what patchA was set internally.
If these differ, it means the user manually called set_patchA() so we skip the override and respect their choice.
I've also added a test case to cover this behaviour.

1.  Add 2 blank lines before function definition
2.  Split long comment line to stay within 80 chars
Only update patchA internally if user has not manually set it.
@dikshajangra12918-oss dikshajangra12918-oss marked this pull request as draft April 5, 2026 11:39
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.

[Bug]: setting patchA of Annotation.arrow_patch has no effect

2 participants