Python 在熊猫的散布矩阵中添加回归线

Python 在熊猫的散布矩阵中添加回归线,python,pandas,matplotlib,scatter-matrix,Python,Pandas,Matplotlib,Scatter Matrix,我在这个问题上发现了很多新闻,但没有人提出我的理由。 我有一个相当大的数据框,我想在其中添加回归线,在网格的另一侧,只将相关系数放在空白处 df=pd.DataFrame(np.concatenate(Arr)) df a b c d e f g h 0 94.122932 87.930649 57.192429 35.844883 57.971062 65.494003 52.297470 52.553162 1 92.2310

我在这个问题上发现了很多新闻,但没有人提出我的理由。 我有一个相当大的数据框,我想在其中添加回归线,在网格的另一侧,只将相关系数放在空白处

df=pd.DataFrame(np.concatenate(Arr))
df

a   b   c   d   e   f   g   h
0   94.122932   87.930649   57.192429   35.844883   57.971062   65.494003   52.297470   52.553162
1   92.231049   87.693893   53.804562   33.005547   52.124733   56.096642   48.072334   46.176899
2   89.846649   87.448158   49.858879   29.900572   46.716476   44.890785   44.026333   40.420742
3   87.181229   87.291374   46.363262   27.649641   41.478992   36.512981   40.489635   35.537495
4   85.915497   87.230659   43.459812   25.325624   37.368202   30.755083   37.228760   31.470888
...

axes = pd.plotting.scatter_matrix(df)
for i in range(np.shape(axes)[0]):
    for j in range(np.shape(axes)[1]):
        if i < j:
            axes[i,j].set_visible(False)
df=pd.DataFrame(np.concatenate(Arr))
df
a b c d e f g h
0   94.122932   87.930649   57.192429   35.844883   57.971062   65.494003   52.297470   52.553162
1   92.231049   87.693893   53.804562   33.005547   52.124733   56.096642   48.072334   46.176899
2   89.846649   87.448158   49.858879   29.900572   46.716476   44.890785   44.026333   40.420742
3   87.181229   87.291374   46.363262   27.649641   41.478992   36.512981   40.489635   35.537495
4   85.915497   87.230659   43.459812   25.325624   37.368202   30.755083   37.228760   31.470888
...
轴=局部放电绘制散射矩阵(df)
对于范围内的i(np.形状(轴)[0]):
对于范围内的j(np.形状(轴)[1]):
如果i


如何添加它?

最简单的方法是使用seaborn的
PairGrid

from scipy.stats import pearsonr
def reg_coef(x,y,label=None,color=None,**kwargs):
    ax = plt.gca()
    r,p = pearsonr(x,y)
    ax.annotate('r = {:.2f}'.format(r), xy=(0.5,0.5), xycoords='axes fraction', ha='center')
    ax.set_axis_off()

iris = sns.load_dataset("iris")
g = sns.PairGrid(iris)
g.map_diag(sns.distplot)
g.map_lower(sns.regplot)
g.map_upper(reg_coef)

最简单的方法是使用seaborn的
PairGrid

from scipy.stats import pearsonr
def reg_coef(x,y,label=None,color=None,**kwargs):
    ax = plt.gca()
    r,p = pearsonr(x,y)
    ax.annotate('r = {:.2f}'.format(r), xy=(0.5,0.5), xycoords='axes fraction', ha='center')
    ax.set_axis_off()

iris = sns.load_dataset("iris")
g = sns.PairGrid(iris)
g.map_diag(sns.distplot)
g.map_lower(sns.regplot)
g.map_upper(reg_coef)

非常感谢您的回复,在对我的“df”进行一些测试时,我注意到,当我将轴设置在0到255之间时,点云的图像质量损失很大。另外,我不知道如何更改每个散点的颜色。非常感谢您的回复,对我的“df”进行了一些测试。我注意到,当我将轴设置在0到255之间时,点云在图像质量方面损失了很多。此外,我不知道如何更改每个散点的颜色。