Coordinates of box of annotations in matplotlib

matplotlib, python

Solution

ax.figure.canvas.draw()
bbox = x.get_window_extent()

will return a `Bbox` object for your text in display units (the `draw` is necessary so that the text is rendered and actually has a display size). You can then use the transforms to convert it to which ever coordinate system you want. Ex

bbox_data = ax.transData.inverted().transform(bbox) 

Problem

How can I get the coordinates of the box displayed in the following plot? ``` fig, ax = subplots() x = ax.annotate('text', xy=(0.5, 0), xytext=(0.0,0.7), ha='center', va='bottom', bbox=dict(boxstyle='round', fc='gray', alpha=0.5), arrowprops=dict(arrowstyle='->', color='blue')) ``` I tried to inspect the properties of this object, but I couldn't find something suited to this purpose. There is a property called `get_bbox_patch()` which could be on the right track, however, I get results in a different coordinate system (or associated to a different property) ``` y = x.get_bbox_patch() y.get_width() 63.265625 ``` Thanks a lot!

Original source