Python Seaborn Pairplot Pearsons P统计

Python Seaborn Pairplot Pearsons P统计,python,matplotlib,scipy,seaborn,Python,Matplotlib,Scipy,Seaborn,作为python/seaborn/scipy.stats/matplotlib.pyplot等的新手,我一直在完成一项数据分析任务 这个链接帮助我通过pearsons R分数呈现变量之间的关系。 然而,由于皮尔逊测试的输出也应该有一个p值,以表明统计意义,我正在寻找一种方法,将p值添加到我的图上的注释中 g = sns.pairplot(unoutlieddata, vars=['bia', 'DW', 'HW', 'jackson', 'girths'], kind="reg") def

作为python/seaborn/scipy.stats/matplotlib.pyplot等的新手,我一直在完成一项数据分析任务

这个链接帮助我通过pearsons R分数呈现变量之间的关系。 然而,由于皮尔逊测试的输出也应该有一个p值,以表明统计意义,我正在寻找一种方法,将p值添加到我的图上的注释中

g = sns.pairplot(unoutlieddata, vars=['bia', 'DW', 'HW', 'jackson', 'girths'], kind="reg")

def corrfunc(x, y, **kws):
    r, _ = sps.pearsonr(x, y)
    ax = plt.gca()
    ax.annotate("r = {:.2f}".format(r),
                xy=(.1, .9), xycoords=ax.transAxes)

g.map(corrfunc)
sns.plt.show()
显示的是我提供的链接格式的代码。 sps=scipy.stats。未输出数据是一个数据帧,它已被过滤以删除异常值

任何想法都会很棒


关于

不确定是否有人会看到这一点,但在与了解更多的人交谈后,答案如下

代码 结果

多亏了编辑这个问题的人,所以这个问题也很有意义:很抱歉,原来是粗略的格式:我的第一个问题,正如我所说的,我是新手,如果你附上输出图进行说明,那将很有帮助。
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import pearsonr

def corrfunc(x, y, **kws):
    (r, p) = pearsonr(x, y)
    ax = plt.gca()
    ax.annotate("r = {:.2f} ".format(r),
                xy=(.1, .9), xycoords=ax.transAxes)
    ax.annotate("p = {:.3f}".format(p),
                xy=(.4, .9), xycoords=ax.transAxes)

df = sns.load_dataset("iris")
df = df[df["species"] == "setosa"]
graph = sns.pairplot(df)
graph.map(corrfunc)
plt.show()