Python 您所在的位置:网站首页 春运数据统计python Python

Python

2024-04-22 03:39| 来源: 网络整理| 查看: 265

转载!

原文:Python-数据统计分析的显著性标注

今天,小编给大家带来的是如何使用Python-Seaborn进行显著性统计图表绘制,详细内容如下:

Python-Seaborn自定义函数绘制Python-statannotations库添加显著性标注Python-Seaborn 自定义函数绘制

我们可以通过自定义绘图函数的方式在统计图表中添加显著性标注,这里我们直接使用Seaborn自带的iris数据集进行绘制,具体内容如下:

自定义P值和星号对应关系

由于是完全的自定义,这里需要定义一个函数将P值结果和对应星号进行转化,代码如下:

def convert_pvalue_to_asterisks(pvalue): if pvalue

「样例二」:

import seaborn as sns import matplotlib.pyplot as plt plt.rcParams['font.family'] = ['Times New Roman'] plt.rcParams["axes.labelsize"] = 18 #palette=['#0073C2FF','#EFC000FF'] palette=['#E59F01','#56B4E8'] #palette = ["white","black"] fig,ax = plt.subplots(figsize=(5,4),dpi=100,facecolor="w") ax = sns.barplot(x="order",y="value",hue="class",data=group_data_p,palette=palette,ci="sd", capsize=.1,errwidth=1,errcolor="k",ax=ax, **{"edgecolor":"k","linewidth":1}) # 添加P值 box_pairs = [(("one","type01"),("two","type01")), (("one","type02"),("two","type02")), (("one","type01"),("three","type01")), (("one","type02"),("three","type02")), (("two","type01"),("three","type01")), (("two","type02"),("three","type02"))] annotator = Annotator(ax, data=group_data_p, x="order",y="value",hue="class", pairs=box_pairs) annotator.configure(test='t-test_ind', text_format='star',line_height=0.03,line_width=1) annotator.apply_and_annotate()

当然,还可以设置灰色系颜色,如下:

「样例三」如果针对组间数据进行统计分析,可以设置pairs参数据如下:

box_pairs = [(("one","type01"),("one","type02")), (("two","type01"),("two","type02")), (("three","type01"),("three","type02"))]

其他比如抖动图、横向分组柱形图等,可视化结果如下:

参考资料

[1]

Python-statannotations官网:https://github.com/trevismd/statannotations。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有