【问题标题】:Statistical significance on matplotlib / seaborn graph?matplotlib / seaborn 图的统计意义?
【发布时间】:2019-10-15 04:29:55
【问题描述】:

我完成了对数据的分析,并希望使用t-test_ind 来证明它们具有统计显着性。但是,除了 (How does one insert statistical annotations (stars or p-values) into matplotlib / seaborn plots?) 中引用的内容之外,我没有发现任何功能可以显示这一点:

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
from statannot import add_stat_annotation

ax = sns.barplot(x=x, y=y, order=order)
add_stat_annotation(ax, data=df, x=x, y=y,
                    boxPairList=[(order[0], order[1]), (order[0], order[2])],
                    test='t-test_ind',
                    textFormat='star',
                    loc='outside')

但是,使用这种方法时,每当我尝试使用 plt.savefig() 保存绘图时,使用 add_stat_annotation 的附加意义都会被丢弃(matplotlib 似乎无法识别添加的注释)。使用 loc='inside' 选项会弄乱我的情节,所以它不是一个真正的选项。

因此,我想问是否有一些更简单的方法可以直接在 matplotlib/seaborn 中添加重要性,或者您是否可以 plt.savefig() 有足够的边框/填充来包含所有内容。

【问题讨论】:

    标签: python matplotlib statistics seaborn


    【解决方案1】:

    这主要是一个 xlabel 切断问题。所以在未来的应用程序中,我会使用来自 webermarcolivier/statannot 的add_stat_annotation。要保存您的文件,请使用以下方法之一:

    import matplotlib.pyplot as plt
    
    plt.tight_layout() # Option 1
    plt.autoscale()    # Option 2
    plt.savefig('filename.png', bbox_inches = "tight") # Option 3
    

    希望这将有助于某人将来使用。

    【讨论】:

      猜你喜欢
      • 2020-09-28
      • 2020-02-22
      • 1970-01-01
      • 2016-08-03
      • 2016-08-25
      • 2017-09-21
      • 2020-09-22
      • 1970-01-01
      • 2019-01-19
      相关资源
      最近更新 更多