You can get the text size by get_window_extent
of the text object. This will return the bounding box of the text in display coordinates (i.e. pixels), but to get the pixel position you obviously first need to draw the text. Doing so by canvas.draw
caches the renderer, so you don't need to provide a renderer to get_window_extent
(valid for Windows and Linux, for macOS see update 3 below).
import matplotlib.pylab as pylab
fig = pylab.figure()
x, y = 5, 7
text = 'label'
pylab.plot(x, y, 'k.')
t = pylab.text(x, y, text, color='red')
fig.canvas.draw()
print(t.get_window_extent())
pylab.show()
On my setup this results in
Bbox(x0=328.0, y0=234.60000000000036, x1=361.75, y1=248.60000000000036)
Update (see comments below):
import matplotlib.pylab as pylab
fig = pylab.figure()
x, y = 5, 7
text = 'label'
pylab.plot(x, y, 'k.')
t = pylab.text(x, y, text, color='red')
fig.canvas.draw()
bbox = t.get_window_extent()
pylab.plot([bbox.x0, bbox.x1, bbox.x1, bbox.x0, bbox.x0],
[bbox.y0, bbox.y0, bbox.y1, bbox.y1, bbox.y0],
'r-',
transform=None)
pylab.show()
Update 2: In order to get the bbox in data coords, you can use the inverted axes tranform, but you'll have to fix the x and y axes limits before adding the box, otherwise it'll trigger a rescaling of the axes.
import matplotlib.pylab as pylab
fig = pylab.figure()
x, y = 5, 7
text = 'label'
pylab.plot(x, y, 'k.')
xl, yl = pylab.xlim(),pylab.ylim()
t = pylab.text(x, y, text, color='red')
fig.canvas.draw()
bbox = pylab.gca().transData.inverted().transform_bbox(t.get_window_extent())
pylab.plot([bbox.x0, bbox.x1, bbox.x1, bbox.x0, bbox.x0],
[bbox.y0, bbox.y0, bbox.y1, bbox.y1, bbox.y0],
'r-')
pylab.xlim(xl)
pylab.ylim(yl)
pylab.show()

Update 3: For macOS you need to explicitly pass a renderer to get_windows_extent
(see here), i.e. the above examples only work as is on Windows and Linux. The following will work on all systems:
import matplotlib.pylab as pylab
fig = pylab.figure()
x, y = 5, 7
text = 'label'
pylab.plot(x, y, 'k.')
xl, yl = pylab.xlim(),pylab.ylim()
t = pylab.text(x, y, text, color='red')
renderer = fig.canvas.get_renderer()
bbox = pylab.gca().transData.inverted().transform_bbox(t.get_window_extent(renderer))
pylab.plot([bbox.x0, bbox.x1, bbox.x1, bbox.x0, bbox.x0],
[bbox.y0, bbox.y0, bbox.y1, bbox.y1, bbox.y0],
'r-')
pylab.xlim(xl)
pylab.ylim(yl)
pylab.show()