参考资料:
https://github.com/trevismd/statannotations
关键代码:
import seaborn as sns
from statannotations.Annotator import Annotator
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)
pairs=[("Thur", "Fri"), ("Thur", "Sat"), ("Fri", "Sun")]
annotator = Annotator(ax, pairs, data=df, x=x, y=y, order=order)
annotator.configure(test='Mann-Whitney', text_format='star', loc='outside')
annotator.apply_and_annotate()
官网例子:https://github.com/trevismd/statannotations/blob/master/usage/example.ipynb
属性设置:
(1)annot.configure(test=None, loc='inside')
,设置显著性的位置;