Matplotlib文字尺寸 [英] Matplotlib text dimensions

查看:103
本文介绍了Matplotlib文字尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to determine the dimensions of a matplotlib text object? How can I find the width and height in pixels?

谢谢

编辑:我想我想出了一种方法.我在下面提供了一个示例.

Edit: I think I figured out a way to do this. I've included an example below.

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

这篇关于Matplotlib文字尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆