概述
我在显示坐标中有一个matplotlib.patches.Rectangle对象(条形图中的一个条)的bBox,如下所示:
BBox(array([[ 0.,0.],[ 1.,1.]])
但我希望不是在显示坐标而是数据坐标.我很确定这需要改造.这样做的方法是什么?
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 ]]))
总结
以上是编程之家为你收集整理的python – 在matplotlib中获取数据坐标中的bbox全部内容,希望文章能够帮你解决python – 在matplotlib中获取数据坐标中的bbox所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧