adjustText icon indicating copy to clipboard operation
adjustText copied to clipboard

Arrow - Text alignment along given positions of the text object

Open dansteiert opened this issue 1 year ago • 8 comments

Hi there,

is there an option to define, where the arrow starts from the text? e.g. currently all arrows start at the bottom (y) and middle (x) of the text.

I think it would be nice, to have always the shortest arrow, or somehow set the arrow to a given position in the text (e.g. middle(y) left (x). Is there an option already and I missed this?

I see that in some of your examples, this is done somewhat automatically. I might have this issue, as I set multiple points to the side of the figure and only let them move on the y-axis. I would understand, that updating the arrow, is not necessarily done, but even so, I would expect that the initial position of the arrow would be at the left middle corner.

here are two images to illustrate the issue

grafik grafik

Thank you for your help!

dansteiert avatar Sep 26 '24 09:09 dansteiert

The arrows generally start from the middle of the test, but then they should be clipped by the text bounding box. First of all, can you make sure you are using the latest version, and maybe even try the master version from GitHub? In "normal" cases this shouldn't happen with the latest code, but matplotlib has some weird bug related to that (https://github.com/matplotlib/matplotlib/issues/28316) so in particular cases it can be a problem.

Phlya avatar Sep 26 '24 09:09 Phlya

Thank you for your super fast response -> yeah the update to the github version changed the behaviour, although, not it clips away on the axes boarder

grafik

    adjust_text(texts=anno, 
               x=df[width_column].tolist(),
               y=df["Plotting_position"].tolist(),
               target_x=x, target_y=y, avoid_self=True, 
                # prevent_crossings=True,
                min_arrow_len = 0.2, only_move={"text": "y", "static": "y"},
                arrowprops={"arrowstyle":"->", "color":'r', "lw":0.5},
                max_move=(0, 40),
                force_text=0.3,
                force_explode=0.3,
                # expand_axes=True,
                ensure_inside_axes= False, 
                ax=ax, iter_lim=iter_lim, time_lim=time_lim)

I played around with some things, but did not get it right yet. setting the spines to invisible also did not change something.

dansteiert avatar Sep 26 '24 10:09 dansteiert

Oh interesting. I'll have to investigate, but I wonder whether clipping by text box also clips by Axes limits automatically...

Phlya avatar Sep 26 '24 10:09 Phlya

[arrow.set_clip_on(False) for arrow in patches] using the returend patches and setting this, shows me the clipped arrows again ;) and the text is now well clipped

dansteiert avatar Sep 26 '24 11:09 dansteiert

on the last image I posted, there is also an "issue" of labels having different indentations. I set the x-coord always the same.

and set these options, but somehow, they wiggle (just a bit) but they do. An Idea why this is? here the options regarding the movement I set:

only_move={"text": "y", "static": "y"},
max_move=(0, 40),

Is this a function of the force?

dansteiert avatar Sep 26 '24 11:09 dansteiert

only_move={"text": "y", "static": "y", 'explode':'y', 'pull':''},
max_move=(0, 40),

maybe this helps?

Phlya avatar Sep 26 '24 12:09 Phlya

Also just setting only_move='y' should work for everything

Phlya avatar Sep 26 '24 12:09 Phlya

only_move='y'

this worked perfectly! I guess the explode and/or pull did mess this abit up.

Thank you again for your quick help!

dansteiert avatar Sep 26 '24 13:09 dansteiert