gpt4 book ai didi

python - 在 matplotlib 中自动定位文本框

转载 作者:IT老高 更新时间:2023-10-28 21:32:55 28 4
gpt4 key购买 nike

有没有办法像使用 pyplot.legend() 一样告诉 pyplot.text() 一个位置?

像传奇这样的论点会很棒:

plt.legend(loc="upper left")

我正在尝试使用字母(例如“A”、“B”)标记具有不同轴的子图。我认为必须有比手动估计位置更好的方法。

谢谢

最佳答案

只需使用 annotate 并指定轴坐标。例如,“左上角”将是:

plt.annotate('Something', xy=(0.05, 0.95), xycoords='axes fraction')

您还可以更花哨并指定一个恒定的偏移量:

plt.annotate('Something', xy=(0, 1), xytext=(12, -12), va='top'
xycoords='axes fraction', textcoords='offset points')

更多解释见示例here以及更详细的示例here .

关于python - 在 matplotlib 中自动定位文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7045729/

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