Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrow - Text alignment along given positions of the text object #183

Open
dansteiert opened this issue Sep 26, 2024 · 8 comments
Open

Arrow - Text alignment along given positions of the text object #183

dansteiert opened this issue Sep 26, 2024 · 8 comments

Comments

@dansteiert
Copy link

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!

@Phlya
Copy link
Owner

Phlya commented Sep 26, 2024

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 (matplotlib/matplotlib#28316) so in particular cases it can be a problem.

@dansteiert
Copy link
Author

dansteiert commented Sep 26, 2024

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.

@Phlya
Copy link
Owner

Phlya commented Sep 26, 2024

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

@dansteiert
Copy link
Author

[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
Copy link
Author

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?

@Phlya
Copy link
Owner

Phlya commented Sep 26, 2024

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

maybe this helps?

@Phlya
Copy link
Owner

Phlya commented Sep 26, 2024

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

@dansteiert
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants