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!
xy: This parameter is the point (x, y) to annotate. xytext: This parameter is an optional parameter. It is The position (x, y) to place the text at. xycoords: This parameter is also an optional parameter and contains the string value.
The Axes. annotate() function in axes module of matplotlib library is also used to annotate the point xy with text text.In other word, it i used to placed the text at xy.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With