Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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 如何将图例放在绘图中的点中?_Python_Matplotlib - Fatal编程技术网

Python 如何将图例放在绘图中的点中?

Python 如何将图例放在绘图中的点中?,python,matplotlib,Python,Matplotlib,大家好,我有一个关于matplotlib中的传奇的问题: 我的代码如下: x=[1,2,3,-4,-5] y=[5,-3,6,7,-2] plt.plot([x],[y], marker='o', markersize=6, color="green") plt.grid() plt.axhline(y=0.0,color='black',alpha=0.3) plt.axvline(x=0.0,color='black',alpha=0.3) plt.xlim(-7,7) plt.ylim(

大家好,我有一个关于matplotlib中的传奇的问题:

我的代码如下:

x=[1,2,3,-4,-5]
y=[5,-3,6,7,-2]

plt.plot([x],[y], marker='o', markersize=6, color="green")
plt.grid()
plt.axhline(y=0.0,color='black',alpha=0.3)
plt.axvline(x=0.0,color='black',alpha=0.3)
plt.xlim(-7,7)
plt.ylim(-9,9)
plt.show()
情节是:

现在,我想在该图像的每个点上贴上一些标签,例如:

有可能吗?。提前感谢您的帮助。

使用:

通过使用
arrowprops
参数,可以省略箭头并更改其属性

对于多个点,只需做一个循环:

for label, x, y in zip(labels, data[:, 0], data[:, 1]):
plt.annotate(
    label,
    xy=(x, y), xytext=(-20, 20),
    textcoords='offset points', ha='right', va='bottom',
    bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),
    arrowprops=dict(arrowstyle = '->', connectionstyle='arc3,rad=0'))

您看过吗:?
for label, x, y in zip(labels, data[:, 0], data[:, 1]):
plt.annotate(
    label,
    xy=(x, y), xytext=(-20, 20),
    textcoords='offset points', ha='right', va='bottom',
    bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),
    arrowprops=dict(arrowstyle = '->', connectionstyle='arc3,rad=0'))