【2.5.4.2】statannot--boxplot显著性标注
一、安装:
The latest stable release can be installed from PyPI:
pip install statannot
You may instead want to use the development version from Github:
pip install git+https://github.com/webermarcolivier/statannot.git
二、说明:
在boxplot中补充显著性差异
import statannot
statannot.add_stat_annotation(
ax,
data=df,
x=x,
y=y,
hue=hue,
box_pairs=[
(("Biscoe", "Male"), ("Torgersen", "Female")),
(("Dream", "Male"), ("Dream", "Female")),
],
test="t-test_ind",
text_format="star",
loc="outside",
)
三、示例

代码
import seaborn as sns
from statannot import add_stat_annotation
df = sns.load_dataset("tips")
x = "day"
y = "total_bill"
order = ['Sun', 'Thur', 'Fri', 'Sat']
ax = sns.boxplot(data=df, x=x, y=y, order=order)
test_results = add_stat_annotation(ax, data=df, x=x, y=y, order=order,
box_pairs=[("Thur", "Fri"), ("Thur", "Sat"), ("Fri", "Sun")],
test='Mann-Whitney', text_format='star',
loc='outside', verbose=2)
test_results
参考资料:
药企,独角兽,苏州。团队长期招人,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn
