是否可以在
seaborn.stipplot
中标注每个点?我的数据在pandas
。我意识到注释适用于matplotlib
,但我没有发现它在这种情况下有效。
seaborn
是 matplotlib
的高级 API,因此将返回的 axes
分配给一个别名,然后使用带有 .annotate
的对象。
这个例子改编自
seaborn
文档here.
测试于
python 3.11.2
、pandas 2.0.0
、matplotlib 3.7.1
、seaborn 0.12.2
import seaborn as sns
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')