在 matplotlib 中自动定位文本框 [英] automatically position text box in matplotlib
本文介绍了在 matplotlib 中自动定位文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法像 pyplot.legend() 那样告诉 pyplot.text() 一个位置?
Is there a way of telling pyplot.text() a location like you can with pyplot.legend()?
像legend论证这样的东西会很好:
Something like the legend argument would be excellent:
plt.legend(loc="upper left")
我正在尝试使用字母(例如A"、B")标记具有不同轴的子图.我认为一定有比手动估计位置更好的方法.
I am trying to label subplots with different axes using letters (e.g. "A","B"). I figure there's got to be a better way than manually estimating the position.
谢谢
推荐答案
当我最初发布问题时,我不确定这是否可用,但现在实际上可以使用 loc 参数.下面是一个例子:
I'm not sure if this was available when I originally posted the question but using the loc parameter can now actually be used. Below is an example:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.offsetbox import AnchoredText
# make some data
x = np.arange(10)
y = x
# set up figure and axes
f, ax = plt.subplots(1,1)
# loc works the same as it does with figures (though best doesn't work)
# pad=5 will increase the size of padding between the border and text
# borderpad=5 will increase the distance between the border and the axes
# frameon=False will remove the box around the text
anchored_text = AnchoredText("Test", loc=2)
ax.plot(x,y)
ax.add_artist(anchored_text)
plt.show()
这篇关于在 matplotlib 中自动定位文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文