adjustText
adjustText copied to clipboard
Arrow color to text color?
Hi,
I found this package from http://stackoverflow.com/a/34762716/712624 and I have to say, it's amazing! I was trying to do this myself, manually, and when I realized how not-simple it was, I luckily stumbled upon this project. It does a great job!
The only downside seems to be that I can't set the arrowprops for each line. For example, I want the arrow color to match the text color, but since I pass adjust_text a list of text objects, I can't pass data for each object individually.
I realize that solving this would seem a bit hacky, but is it something you'd be willing to implement or accept a patch for?
Thanks for this great project!
Hi, Thank you, I am glad you like it.
Yes, currently it is not possible... I would be happy to accept a PR for this, I myself don't have time right now to try and implement this. In my opinion, the best solution would be fixing the other issue you reported, then all properties of annotations can be set during their creation as required, and here we then only move them.
Note: you can set the color of the arrows according to their respective labels ex post by:
- keeping track of the artists added to
ax.textsafteradjust_text, and then - zipping each new artist with the old ones and copying the color:
nlabels = len(ax.texts)
adjust_text(ax.texts, ...)
for new, old in zip(ax.texts[nlabels:], ax.texts):
new.arrow_patch.set_color(old.get_color())
(If your blueprint is a different kind of object, like ax.patches, you might need to use get_edgecolor() or the like.)
Example:

@bertsky AdjustText doesn't have arrowpatch attribute, how were you able to accomplish changing the color of the arrow? I have the same problem but with a graph
@edlemus what do you mean adjust_text does not have an attribute? It's just a function on matplotlib.text.Text instances.
See https://github.com/i008/COCO-dataset-explorer/blob/df82a833163d7acc131eefb5264684cb2cc627b5/vis.py#L116-L119 for example.