2
我知道如何让文本的宽度:如何获得matplotlib文本的宽度,包括填充的边界框?
import matplotlib.pyplot as plt
from matplotlib.patches import BoxStyle
xpos, ypos = 0, 0
text = 'blah blah'
boxstyle = BoxStyle("Round", pad=1)
props = {'boxstyle': boxstyle,
'facecolor': 'white',
'linestyle': 'solid',
'linewidth': 1,
'edgecolor': 'black'}
textbox = plt.text(xpos, ypos, text, bbox=props)
plt.show()
textbox.get_bbox_patch().get_width() # 54.121092459652573
不过,这并没有考虑到的填充。事实上,如果我将填充设置为0,则获得相同的宽度。
boxstyle = BoxStyle("Round", pad=0)
props = {'boxstyle': boxstyle,
'facecolor': 'white',
'linestyle': 'solid',
'linewidth': 1,
'edgecolor': 'black'}
textbox = plt.text(xpos, ypos, text, bbox=props)
plt.show()
textbox.get_bbox_patch().get_width() # 54.121092459652573
我的问题是:我怎么能得到周围框的宽度?或者如何在FancyBoxPatch的情况下获得填充的大小?
非常感谢:-)我花了很长时间寻找这个。 –