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:
BTW, my matplotlib version is 3.4.3
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()
Yes, indeed texts are not considered.
matplotlib/lib/matplotlib/legend.py
Line 815 in 40dea5a
Activity
jklymak commented on Jun 22, 2022
It maybe doesn't unwind the transform to put it in data units instead of transAxes?
ym3141 commented on Jun 22, 2022
Nope, got the same issue with the following code:
jklymak commented on Jun 22, 2022
Yes, indeed texts are not considered.
matplotlib/lib/matplotlib/legend.py
Line 815 in 40dea5a