Annotate points in Seaborn stripplot with Pandas d

2019-02-20 05:54发布

Is it possible to annotate each point on a stripplot in seaborn? My data is in the pandas dataframe. I realize that annotate works for matplotlib but I have not found it to work in this case.

1条回答
我只想做你的唯一
2楼-- · 2019-02-20 06:13

You just need to return the axes object. The example below is adapted from the seaborn docs here:

import seaborn as sns

sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
sat_mean = tips.loc[tips['day'] == 'Sat']['total_bill'].mean()

ax = sns.stripplot(x="day", y="total_bill", data=tips)
ax.annotate("Saturday\nMean",
            xy=(2, sat_mean), xycoords='data',
            xytext=(.5, .5), textcoords='axes fraction',
            horizontalalignment="center",
            arrowprops=dict(arrowstyle="->",
                            connectionstyle="arc3"),
            bbox=dict(boxstyle="round", fc="w"),
            )
#ax.get_figure().savefig('tips_annotation.png')

png output

查看更多
登录 后发表回答