快速而肮脏的方法是使用右对齐和顶部对齐的文本,并将其放置在距离轴角的点的固定偏移处:
import matplotlib.pyplot as plt
# Define some names and variables to go in the text box.
xn, yn, cod = 'r', 'p', 'abc'
prec = 2
ccl = [546.35642, 6785.35416]
ect = [12.5235, 13.643241]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.axis([-1, 10, -1, 1])
# Generate text to write.
text1 = "${}_{ {t}} = {:.{p}f} \pm {:.{p}f}\; {c}$".format(xn, ccl[0],
ect[0], c=cod, p=prec)
text2 = "${}_{ {t}} = {:.{p}f} \pm {:.{p}f}\; {c}$".format(yn, ccl[1],
ect[1], c=cod, p=prec)
text = text1 + '\n' + text2
ax.annotate(text, xy=(1, 1), xytext=(-15, -15), fontsize=10,
xycoords='axes fraction', textcoords='offs