Python 向seaborn lmplot添加文本注释

Python 向seaborn lmplot添加文本注释,python,plot,seaborn,Python,Plot,Seaborn,我正在尝试为聚类结果创建seaborn lmplot,数据示例如下所示: ID CA IP clusters 38 10.3 5.6 1 59 10.4 6.1 0 64 10.0 6.6 1 35 10.6 5.6 1 54 10.6 5.6 1 60 10.2 8.2 1 有两个集群,集群0和集群1,我想根据每个分散点上的ID列显示ID。尝试了中添加

我正在尝试为聚类结果创建seaborn lmplot,数据示例如下所示:

    ID   CA     IP  clusters
    38  10.3    5.6   1
    59  10.4    6.1   0
    64  10.0    6.6   1
    35  10.6    5.6   1
    54  10.6    5.6   1
    60  10.2    8.2   1
有两个集群,集群0和集群1,我想根据每个分散点上的ID列显示ID。尝试了中添加文本的功能,但出现错误,说明FacetGrid没有文本功能

seaborn地块代码:

ax = sns.lmplot('CA', 'IP', 
     data=df_tr, 
     fit_reg=False, 
     hue="clusters",  palette="Set1",
     scatter_kws={"marker": "D", "s": 50})

plt.title('Calcium vs Phosporus')
plt.xlabel('CA')
plt.ylabel('IP')
情节是:

问题在于,在您链接的站点中使用此函数可返回matplotlib Axis对象,该对象允许您使用文本函数。但是,seaborn.lmplot返回FaceGrid

因此,您需要获得Facetgrid的轴,您可以使用

fgrid = sns.lmplot(...)
ax = fgrid.axes[0,0]  # fgrid.axes return an array of all axes in the figure, so we index the array
从这里,您可以使用链接中所示的功能