Annotate points in Seaborn stripplot with Pandas dataframe

女生的网名这么多〃 提交于 2019-12-01 11:57:37

问题


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:


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



来源:https://stackoverflow.com/questions/44077661/annotate-points-in-seaborn-stripplot-with-pandas-dataframe

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