pandas scatter matrix display correlation coefficient

匿名 (未验证) 提交于 2019-12-03 01:17:01

问题:

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.

回答1:

A working minimal example

import matplotlib.pyplot as plt import pandas as pd import numpy as np from pandas.tools.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() 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!