You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: setting patchA of Annotation.arrow_patch has no effect #28316
I am trying to improve some edge cases for plotting arrows in adjustText. Without going into details, sometimes I have to use ax.annotate to add arrows instead of directly using FancyArrowPatch. However in this case the arrows are not associated with the text objects and strike through them. I thought I could modify the arrow patch of the Annotation object to point to the corresponding Text object. The object appears to be set correctly, however this doesn't fix the clipping of the arrow! With a regular FancyArrowPatch this procedure works just as expected. Interestingly, if I update other properties (color) it works perfectly.
(As an aside, why do the two arrows have a different style in the example below?)
This is indeed surprising. It's even better to see when using ]-> arrows. Also arrow scales are significantly different in the two approaches. There's something very fishy here.
When immidately drawing the text, alignment is correct
It's not just text extent, the overall position is not updated as well, as we can see when the inital xytext does not coincide with the text that is later added
# modified line in original example:
ann = ax.annotate('', xy=(0.5, 0.6), xytext=(0.5, 0.5), arrowprops=dict(arrowstyle="]->"))
It seems like the arrow position is correctly computed at creation time but not updated when the text or its extent changes later.
Would it make sense to trigger a recomputation of the arrow position after seting patchA, based on the current text extent?
Or is there a design reason why annotation does not update in the same way as FancyArrowPatch here?
@Phlya why are you doing ax.annotate('', xy=(0.5, 0.6), xytext=xytext, arrowprops=dict(arrowstyle="->")) and then trying to patch in another text?
This does not work as Annotation provides a text itself and "owns" the patchA of the associated arrow, i.e. it sets it at draw time to the bounding box of it's own text, which is empty in your case.
It does seem illogical, but I think the issue is that I couldn't find a way to get the bbox of the text patch and/or a way to modify it... It's been a few years since I wrote that though.
Ah, semi-scratch that (the above is also an issue, which prevents adjustText from using Annotation objects as input instead of Text).
Looking into it a bit now, I think actually the idea is that I wanted to actually use the original provided Text objects and maintain all of their properties (fonts, colours, etc) since they are provided by the user, and not look for a way to replicate all of that when creating Annotation objects instead of the provided Texts.
Thanks for the clarification. So actually you want an arrow from "custom Artist" (your text object) to some point. That's what ConnectionPatch is for. Unfortunately it's currently less flexible than the transforms in Annotation, which makes it not yet a drop-in replacement, but the plan is to enhance that #26440.
Thanks for the clarification sir! I understand now that ConnectionPatch is the right long-term solution. I will look into issue #26440. Should I close this PR?
Activity
Phlya commentedon May 30, 2024
Relevant issue in adjustText Phlya/adjustText#175
timhoffm commentedon May 31, 2024
This is indeed surprising. It's even better to see when using
]->arrows. Also arrow scales are significantly different in the two approaches. There's something very fishy here.When immidately drawing the text, alignment is correct
It's not just text extent, the overall position is not updated as well, as we can see when the inital
xytextdoes not coincide with the text that is later addeddikshajangra12918-oss commentedon Mar 31, 2026
It seems like the arrow position is correctly computed at creation time but not updated when the text or its extent changes later.
Would it make sense to trigger a recomputation of the arrow position after seting patchA, based on the current text extent?
Or is there a design reason why annotation does not update in the same way as FancyArrowPatch here?
timhoffm commentedon Apr 1, 2026
You are welcome to investigate. I project, nobody will be able to answer that question off the top of their head.
Preserve user-set patchA in Annotation.update_positions
timhoffm commentedon Apr 8, 2026
@Phlya why are you doing
ax.annotate('', xy=(0.5, 0.6), xytext=xytext, arrowprops=dict(arrowstyle="->"))and then trying to patch in another text?This does not work as
Annotationprovides a text itself and "owns" the patchA of the associated arrow, i.e. it sets it at draw time to the bounding box of it's own text, which is empty in your case.Phlya commentedon Apr 8, 2026
It does seem illogical, but I think the issue is that I couldn't find a way to get the bbox of the text patch and/or a way to modify it... It's been a few years since I wrote that though.
Phlya commentedon Apr 8, 2026
Ah, semi-scratch that (the above is also an issue, which prevents adjustText from using Annotation objects as input instead of Text).
Looking into it a bit now, I think actually the idea is that I wanted to actually use the original provided Text objects and maintain all of their properties (fonts, colours, etc) since they are provided by the user, and not look for a way to replicate all of that when creating Annotation objects instead of the provided Texts.
Phlya commentedon Apr 8, 2026
FYI here is the code: https://github.com/Phlya/adjustText/blob/aab1e1915f0b995b0b0e53811f6aeedfabbe618a/adjustText/__init__.py#L781
timhoffm commentedon Apr 8, 2026
Thanks for the clarification. So actually you want an arrow from "custom Artist" (your text object) to some point. That's what
ConnectionPatchis for. Unfortunately it's currently less flexible than the transforms in Annotation, which makes it not yet a drop-in replacement, but the plan is to enhance that #26440.dikshajangra12918-oss commentedon Apr 9, 2026
Thanks for the clarification sir! I understand now that ConnectionPatch is the right long-term solution. I will look into issue #26440. Should I close this PR?
timhoffm commentedon Apr 12, 2026
@dikshajangra12918-oss yes, please the related PR it's not the correct fix fox this scenario.
Preserve user-set patchA in Annotation.update_positions