# 【2.1.9】成对图（pairwise-plot）

### 例一

# Load Dataset

# Plot
plt.figure(figsize=(10,8), dpi= 80)
sns.pairplot(df, kind="scatter", hue="species", plot_kws=dict(s=80, edgecolor="white", linewidth=2.5))
plt.show()


### 例2

# Load Dataset

# Plot
plt.figure(figsize=(10,8), dpi= 80)
sns.pairplot(df, kind="reg", hue="species")
plt.show()


### 例3

infile = 'hsc.csv'

import numpy as np
import matplotlib.pyplot as plt
# Seaborn visualization library
import seaborn as sns
# Create the default pairplot
#sns.pairplot(df)
# Function to calculate correlation coefficient between two arrays

def corr(x, y, **kwargs):
# Calculate the value

#remove nan
dt = {'x':x,'y':y}
df_1 = pd.DataFrame(dt)
df_2 = df_1.dropna()
x = df_2['x']
y = df_2['y']
coef = np.corrcoef(x, y)[0][1]
# Make the label

label = r'$\rho$ = ' + str(round(coef, 2))
# Add the label to the plot
ax = plt.gca()
ax.annotate(label, xy = (0.2, 0.95), size = 20, xycoords = ax.transAxes)

grid = sns.PairGrid(data= df)
# Map the plots to the locations
grid = grid.map_lower(plt.scatter)
grid = grid.map_lower(corr)
grid = grid.map_upper(sns.kdeplot, cmap = 'Blues')
grid = grid.map_diag(plt.hist, bins = 10, edgecolor =  'k');
plt.savefig(result_pic)