最佳答案
我不确定你是如何在显示坐标中得到BBox的.用户与之交互的几乎所有内容都在数据坐标中(对我来说看起来像轴或数据坐标,而不是显示像素).以下内容应充分说明适用于BBox的转换:
from matplotlib import pyplot as plt
bars = plt.bar([1,2,3],[3,4,5])
ax = plt.gca()
fig = plt.gcf()
b = bars[0].get_bBox() # bBox instance
print b
# Box in data coords
#BBox(array([[ 1.,0. ],# [ 1.8,3. ]]))
b2 = b.transformed(ax.transData)
print b2
# Box in display coords
#BBox(array([[ 80.,48. ],# [ 212.26666667,278.4 ]]))
print b2.transformed(ax.transData.inverted())
# Box back in data coords
#BBox(array([[ 1.,3. ]]))
print b2.transformed(ax.transAxes.inverted())
# Box in axes coordinates
#BBox(array([[ 0.,0. ],# [ 0.26666667,0.6 ]]))