您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – 在matplotlib中获取数据坐标中的bbox

5b51 2022/1/14 8:21:22 python 字数 2914 阅读 474 来源 www.jb51.cc/python

我在显示坐标中有一个matplotlib.patches.Rectangle对象(条形图中的一个条)的bbox,如下所示:Bbox(array([[ 0., 0.],[ 1., 1.]]) 但我希望不是在显示坐标而是数据坐标.我很确定这需要改造.这样做的方法是什么?最佳答案我不确定你是如何在显示坐标中得到Bbox的.用户与之交互的几乎所有内容都在数据坐标

概述

我在显示坐标中有一个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所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶