matplotlib文字大小[左,下,宽,高](matplotlib Text size [left, bottom, width, height])

我想知道如何准确计算matplotlib.Text的大小。

# this gives the position of the center of the text in the figure xy = text.get_position() # text size like in axes.get_position() [left, bottom, width, height] = text.???

对于文本,它可能更复杂,因为所有都取决于字体,fontsize等。我在想我可以使用text.get_bbox_patch()或text.get_clip_box()但两者都返回None

I wonder how to calculate exactly the size of a matplotlib.Text.

# this gives the position of the center of the text in the figure xy = text.get_position() # text size like in axes.get_position() [left, bottom, width, height] = text.???

For the text it might be more complicated because all depends on the font, fontsize etc. I was thinking that I can use text.get_bbox_patch() or text.get_clip_box() but both return None

最满意答案

text.get_window_extent()是要走的路。

由于某些原因,text.get_bbox_path()始终返回None

text.get_window_extent() is the way to go.

for some reasons text.get_bbox_path() is always returning None

matplotlib文字大小[左,下,宽,高](matplotlib Text size [left, bottom, width, height])

我想知道如何准确计算matplotlib.Text的大小。

# this gives the position of the center of the text in the figure xy = text.get_position() # text size like in axes.get_position() [left, bottom, width, height] = text.???

对于文本,它可能更复杂,因为所有都取决于字体,fontsize等。我在想我可以使用text.get_bbox_patch()或text.get_clip_box()但两者都返回None

I wonder how to calculate exactly the size of a matplotlib.Text.

# this gives the position of the center of the text in the figure xy = text.get_position() # text size like in axes.get_position() [left, bottom, width, height] = text.???

For the text it might be more complicated because all depends on the font, fontsize etc. I was thinking that I can use text.get_bbox_patch() or text.get_clip_box() but both return None

最满意答案

text.get_window_extent()是要走的路。

由于某些原因,text.get_bbox_path()始终返回None

text.get_window_extent() is the way to go.

for some reasons text.get_bbox_path() is always returning None