gpt4 book ai didi

pandas - 使用 Pandas 数据框在 Seaborn stripplot 中注释点

转载 作者:行者123 更新时间:2023-12-03 21:27:36 24 4
gpt4 key购买 nike

是否可以在 seaborn 的带状图上标注每个点?我的数据在 Pandas 数据框中。我知道注释适用于 matplotlib,但我发现它在这种情况下不起作用。

最佳答案

您只需要返回 axes 对象。下面的示例改编自 seaborn 文档 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

关于pandas - 使用 Pandas 数据框在 Seaborn stripplot 中注释点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44077661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com