pandas 散射矩阵显示相关系数 [英] pandas scatter matrix display correlation coefficient

查看:103
本文介绍了 pandas 散射矩阵显示相关系数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来显示大熊猫散布矩阵的下三角或上三角的相关系数-有人可以将我指向正确的方向吗?谢谢.

I've tried to find a way to display correlation coefficients in the lower or upper tri of a pandas scatter matrix - can someone point me in the right direction? Thank you.

推荐答案

有效的最小示例

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from pandas.plotting import scatter_matrix
df = pd.DataFrame(np.random.randn(100, 4), columns=['a', 'b', 'c', 'd'])
axes = scatter_matrix(df, alpha=0.5, diagonal='kde')
corr = df.corr().as_matrix()
for i, j in zip(*plt.np.triu_indices_from(axes, k=1)):
    axes[i, j].annotate("%.3f" %corr[i,j], (0.8, 0.8), xycoords='axes fraction', ha='center', va='center')
plt.show()

这篇关于 pandas 散射矩阵显示相关系数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆