matplotlib中注释框的坐标

Rob*_*ith 6 python matplotlib

如何获得下图中显示的框的坐标?

在此输入图像描述

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'))
Run Code Online (Sandbox Code Playgroud)

我试图检查这个对象的属性,但我找不到适合这个目的的东西.有一个属性get_bbox_patch()可以在正确的轨道上,但是,我得到一个不同的坐标系统(或与不同的属性相关联)

y = x.get_bbox_patch()
y.get_width()
63.265625
Run Code Online (Sandbox Code Playgroud)

非常感谢!

tac*_*ell 5

ax.figure.canvas.draw()
bbox = x.get_window_extent()
Run Code Online (Sandbox Code Playgroud)

将以Bbox显示单位返回文本的对象(这draw是必要的,以便呈现文本并实际具有显示大小).然后,您可以使用变换将其转换为您想要的坐标系.防爆

bbox_data = ax.transData.inverted().transform(bbox) 
Run Code Online (Sandbox Code Playgroud)