Pandas scatter matrix mapping correlation coefficient

I tried to find a way to display the correlation coefficients in the bottom or top trit of the pandas scatter matrix - can someone point me in the right direction? Thank.

+5


source to share


1 answer


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

+14


source







All Articles