有没有办法像使用 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')
关于python - 在 matplotlib 中自动定位文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7045729/