繁体   English   中英

如何将matplotlib图重新缩放到文本?

[英]How to rescale matplotlib figure to text?

我希望能够自动缩放matplotlib图形,以使任意放置的文本注释可见。 这是一个挑战,因为Patches和Lines以外的艺术家不包括在relim中。 例如,以下文本不在查看区域中。

fig = figure()
ax = fig.add_subplot(111)
t = matplotlib.text.Text(10,10, 'Hello')
ax.add_artist(t)
show()

文档使用update_datalim_numerix 密码提及 ,但如何在数据单元中确定正确的边界框? 有没有一种方法可以告诉我文本边界框的大小? 我如何应对经历过多次转换的艺术家?

您可以将文本相对于轴的地方,如解释在这里

import matplotlib.pyplot as plt
import matplotlib.text as txt

fig = plt.figure()
ax = fig.add_subplot(111)
t = txt.Text(0.5,0.5, 'Hello',transform=ax.transAxes)
ax.add_artist(t)
plt.show()

无论您如何更改轴,此示例都会将文本始终放在绘图的中心。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM