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

Allow text outside figure box #91

Open
DasHammett opened this issue Apr 2, 2020 · 1 comment
Open

Allow text outside figure box #91

DasHammett opened this issue Apr 2, 2020 · 1 comment

Comments

@DasHammett
Copy link

Hi,
It would seem adjust_text forces the text to be inside the plot figure, but this behaviour have issues with what I would like to achieve.

I want to build a line chart with text at the end of each line identifying the characteristic.

I use the following code to achieve it, and it works fine:

text = []
for col in df.columns:                                                     
    text.append(plt.text(plt.xticks()[0][-1], df[col].iloc[-1],col))

This put the text outside of the figure plot, right beside each line. The problem arises when the lines end up too close and the text overlap.

I have been trying adjust_text with several options and the best I could achieve was with this

adjust_text(text,
            arrowprops=dict(arrowstyle="->", color='r', lw=0.5),           
            autoalign='', 
            only_move={'points':'y', 'text':'y'}) 

but this moves all labels inside the plot. In fact, all options I tried put them inside.

Is there an option/way to put them outside?

An example of what I want to achieve is here:
https://stackoverflow.com/questions/49237522/how-to-annotate-end-of-lines-using-python-and-matplotlib

Thanks

@Phlya
Copy link
Owner

Phlya commented Apr 2, 2020

No, at the moment there is no option - adjustText will always force texts to be inside the axes. You can try adding second axes just for texts. I'll see if it's easy to add an option to allow texts to extend bring beyond axes limits when I have time.

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