Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Legend with "loc=best" does not try to avoid text #23323

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

Closed
ym3141 opened this issue Jun 22, 2022 · 3 comments · Fixed by #27469
Closed

Legend with "loc=best" does not try to avoid text #23323

ym3141 opened this issue Jun 22, 2022 · 3 comments · Fixed by #27469
Milestone

Comments

@ym3141
Copy link

ym3141 commented Jun 22, 2022

I had this issue, and found almost exactly the same problem on Stack Overflow (link)

Briefly, the pyplot.legend does not try to avoid pyplot.text. Here is a minimal example:

import matplotlib.pyplot as plt
x = [1, 2]
plt.plot(x, x, label='plot name')
plt.gca().text(0.05, 0.95, 'some text', transform=plt.gca().transAxes, verticalalignment='top')
plt.gca().legend(loc='best')
plt.show()

resulting in legend overlaying the text like this:
Figure_1

BTW, my matplotlib version is 3.4.3

@jklymak
Copy link
Member

jklymak commented Jun 22, 2022

It maybe doesn't unwind the transform to put it in data units instead of transAxes?

@ym3141
Copy link
Author

ym3141 commented Jun 22, 2022

It maybe doesn't unwind the transform to put it in data units instead of transAxes?

Nope, got the same issue with the following code:

import matplotlib.pyplot as plt
x = [1, 2]
plt.plot(x, x, label='plot name')
plt.gca().text(1.05, 2, 'some text', verticalalignment='top')
plt.gca().legend(loc='best')
plt.show()

@jklymak
Copy link
Member

jklymak commented Jun 22, 2022

Yes, indeed texts are not considered.

def _auto_legend_data(self):

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