本文介绍了如何将统计注释(星号或 p 值)插入到 matplotlib/seaborn 图中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这似乎是一个微不足道的问题,但我已经搜索了一段时间,似乎无法找到答案.它似乎也应该成为这些包的标准部分.有谁知道是否有一种标准方法可以在 seaborn 的分布图之间包含统计注释?
This seems like a trivial question, but I've been searching for a while and can't seem to find an answer. It also seems like something that should be a standard part of these packages. Does anyone know if there is a standard way to include statistical annotation between distribution plots in seaborn?
例如,在两个框或群图之间?
For example, between two box or swarmplots?
推荐答案
这里是如何向 Seaborn 箱形图添加统计注释:
Here how to add statistical annotation to a Seaborn box plot:
import seaborn as sns, matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.boxplot(x="day", y="total_bill", data=tips, palette="PRGn")
# statistical annotation
x1, x2 = 2, 3 # columns 'Sat' and 'Sun' (first column: 0, see plt.xticks())
y, h, col = tips['total_bill'].max() + 2, 2, 'k'
plt.plot([x1, x1, x2, x2], [y, y+h, y+h, y], lw=1.5, c=col)
plt.text((x1+x2)*.5, y+h, "ns", ha='center', va='bottom', color=col)
plt.show()
结果如下:
这篇关于如何将统计注释(星号或 p 值)插入到 matplotlib/seaborn 图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!