Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib沿打印线打印标签_Python_Matplotlib_Plot - Fatal编程技术网

Python 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

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.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')