使用matplotlib库中的text()函数来自定义文本标签的位置和大小。
示例代码:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5] y = [10, 8, 6, 4, 2]
fig, ax = plt.subplots() ax.plot(x, y)
ax.text(3, 6, 'Sample Label', fontsize=14, ha='center', va='center')
plt.show()
解释:上述代码中,使用text()函数来添加一个位于(3,6)的文本标签,字体大小为14,水平方向居中,垂直方向居中。可以通过修改text()函数的参数来自定义标签的位置和大小。
上一篇:标签位置和/或对齐