Seaborn FacetGrid PointPlot Label Data Points

六月ゝ 毕业季﹏ 提交于 2019-11-28 10:31:53

I wouldn't know what ind is either. But if the aim is to annotate the points with their coordinates, you may use ax.annotate inside a function that is mapped to the FacetGrid as follows:

import matplotlib.pyplot as plt
import seaborn as sns

attend = sns.load_dataset("attention")
sns.set_style("whitegrid", {'axes.grid' : False,'axes.edgecolor':'none'})
g = sns.FacetGrid(attend, col="subject", col_wrap=5,
                  size=1.5, ylim=(0, 10))

def f(x,y, **kwargs):
    ax = sns.pointplot(x,y,**kwargs)
    ax.axhline(5, alpha=0.5, color='grey')
    for i in range(len(x)):
        ax.annotate(str(y.values[i]), xy=(x.values[i]-1, y.values[i]),fontsize=8,
                    xytext = (0,10), textcoords="offset points",
                color=kwargs.get("color","k"), 
                bbox=dict(pad=.9,alpha=0.2, fc='limegreen',color='none'),
                va='center', ha='center',weight='bold')

g.map(f, "solutions", "score", scale=.7)

plt.show()

Possibly, you need to use xy=(i, y.values[i]) in the annotation, depending on what the data looks like.

Note that this also answers your previous question by putting the axhline in that function as well.

If the aim is to replace the points by the annotations, use xytext = (0,0) or leave that argument out completely; then also keep bbox=dict(pad=.9,alpha=1, fc='w',color='none') and use markers="" in the function call:

import matplotlib.pyplot as plt
import seaborn as sns

attend = sns.load_dataset("attention")
sns.set_style("whitegrid", {'axes.grid' : False,'axes.edgecolor':'none'})
g = sns.FacetGrid(attend, col="subject", col_wrap=5,
                  size=1.5, ylim=(0, 10))

def f(x,y, **kwargs):
    ax = sns.pointplot(x,y,**kwargs)
    ax.axhline(5, alpha=0.5, color='grey')
    for i in range(len(x)):
        ax.annotate(str(y.values[i]), xy=(i, y.values[i]),fontsize=8,
                color=kwargs.get("color","k"), 
                bbox=dict(pad=.9,alpha=1, fc='w',color='none'),
                va='center', ha='center',weight='bold')

g.map(f, "solutions", "score", scale=.7, markers="")

plt.show()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!