This might help a bit.
import matplotlib.pyplot as plt f = plt.figure() ax = f.add_subplot(111) ax.plot([0,10], [4,0]) t = ax.text(3.2, 2.1, "testing...")
This should give what you want. If you want to have coordinates along the coordinates of the figure (0..1.0..1), use the inverse of ax.transAxes .
However, there is a little trick in this decision. Excerpt from matplotlib documentation:
Any instance of Text can report its degree in the coordinates of the window (the negative x coordinate is located outside the window), but there is a rub.
The instance of RendererBase, which is used to calculate the size of the text, is still unknown until the picture is drawn (draw ()). After the window is drawn and the text instance knows its renderer, you can call get_window_extent ().
So, before the picture is actually drawn, it seems that there is no way to know the size of the text.
By the way, you may have noticed that instances of Bbox have an overlaps method that can be used to determine if Bbox overlapping with another ( bb1.overlaps(bb2) ). This may be useful in some cases, but it does not answer the question of how much.
If you have rotated texts, it will be difficult for you to see if they overlap, but you probably already know.
source share