问题
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