python中带趋势线和rsquared/相关系数的散布矩阵

2024-04-24 19:35:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用趋势线和r-sqaured绘制一个散点矩阵作为每个散点图的图例。假设以下数据帧:

df = pd.DataFrame(
                  {'x':[2.1,3.1,5.4,8,12,11],
                   'y':[3,5.3,4,6,8,9.1],
                   'c':[7,4,5,2,3,1]
                  }
                 )

熊猫散射矩阵给了我:

pd.plotting.scatter_matrix(df,marker='o')

enter image description here

我可以用海本热图找到决定系数(r2):

import seaborn as sns
corr = df.corr()**2
sns.heatmap(corr,square=True,annot=True)

enter image description here

现在我想在第一个散点矩阵上显示所有这些r2的图例,并在每个图上添加一条趋势线。我想知道有没有办法。你知道吗


Tags: 数据truedataframedf绘制矩阵plotting趋势