Phlya / adjustText

A small library for automatically adjustment of text position in matplotlib plots to minimize overlaps.
https://adjusttext.readthedocs.io/
MIT License
1.49k stars 87 forks source link

adjust_text removes *center* horizontal alignment #148

Closed dekuenstle closed 9 months ago

dekuenstle commented 1 year ago

Whenever I use adjust_text on texts, which should have center alignment, the result is actually left/right or top/bottom aligned–––even if there would be enough space for center alignment. I tried to solve it with the avoid_self and only_move options, but nothing worked.

How can I use center alignment with adjust_text (optimally just in the y direction).

Minimal example

plt.scatter([0, 0.5, 1], [0, 0.5, 1])
texts = []
texts.append(plt.text(0.0, 0.1, 'AAA', ha='center', va='center'))
texts.append(plt.text(0.5, 0.6, 'BBB', ha='center', va='center'))
texts.append(plt.text(1.0, 0.9, 'CCC', ha='center', va='center'))
adjust_text(texts)

Actual result (with adjust_text)

image

Expected result (here without adjust_text):

image

Phlya commented 9 months ago

Sorry, it's been a long time... I suspect it was an old version that was causing this, there you could specify autoalign=False to switch this off. With the latest version on github it shouldn't happen I believe.