Python matplotlib沿打印线打印标签
matplotlib社区的一个: 假设我有一条直线:Python matplotlib沿打印线打印标签,python,matplotlib,plot,Python,Matplotlib,Plot,matplotlib社区的一个: 假设我有一条直线: plot([37, 45], [-0.67778, -0.67778], '--k', lw=1.2) 我是否能够沿直线而不是图例向该直线添加标签?i、 例如,类似于以下内容,但不是等高线图,而是普通线图: 下面是一个简单的例子来说明如何在不考虑外观的情况下完成。有关注释打印的更多信息,请参见此 收益率: import matplotlib.pyplot as plt x = [37, 45]; y = [-0.67778, -0.6777
plot([37, 45], [-0.67778, -0.67778], '--k', lw=1.2)
我是否能够沿直线而不是图例向该直线添加标签?i、 例如,类似于以下内容,但不是等高线图,而是普通线图:
下面是一个简单的例子来说明如何在不考虑外观的情况下完成。有关注释打印的更多信息,请参见此 收益率:
import matplotlib.pyplot as plt
x = [37, 45]; y = [-0.67778, -0.67778]
# as an example for where to place the text we can use the mean
xmean = sum(i for i in x) / float(len(x))
ymean = sum(i for i in y) / float(len(y))
plt.plot(x, y, '--k', lw=1.2)
plt.annotate('some text', xy=(xmean,ymean), xycoords='data')
plt.show() # or plt.savefig('filename.png')