简体   繁体   English

大熊猫散射矩阵显示相关系数

[英]pandas scatter matrix display correlation coefficient

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. 谢谢。

A working minimal example 一个工作最小的例子

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()

http://i.stack.imgur.com/apXPu.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM