gpt4 book ai didi

python - Matplotlib 文本尺寸

转载 作者:IT老高 更新时间:2023-10-28 22:05:36 25 4
gpt4 key购买 nike

是否可以确定 matplotlib 文本对象的尺寸?如何找到以像素为单位的宽度和高度?

谢谢

编辑:我想我想出了一个办法。我在下面提供了一个示例。

import matplotlib as plt

f = plt.figure()
r = f.canvas.get_renderer()
t = plt.text(0.5, 0.5, 'test')

bb = t.get_window_extent(renderer=r)
width = bb.width
height = bb.height

最佳答案

from matplotlib import pyplot as plt

f = plt.figure()
r = f.canvas.get_renderer()
t = plt.text(0.5, 0.5, 'test')

bb = t.get_window_extent(renderer=r)
width = bb.width
height = bb.height

关于python - Matplotlib 文本尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5320205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com