adjustText icon indicating copy to clipboard operation
adjustText copied to clipboard

Arrow color to text color?

Open alphapapa opened this issue 9 years ago • 4 comments

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!

alphapapa avatar Oct 20 '16 19:10 alphapapa

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.

Phlya avatar Oct 21 '16 08:10 Phlya

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.texts after adjust_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 avatar Feb 24 '21 02:02 bertsky

@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 avatar Nov 03 '22 02:11 edlemus

@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.

bertsky avatar Nov 03 '22 07:11 bertsky