1) matplotlib
2) seaborn
sns.heatmap(data , annot=True # Heatmap에 숫자 표기 , fmt='.1f' # Annotation Formatting - 소수점 표기 , linewidth=0.5 # Heatmap 사이 line 두께 , cmap='Blues |YlGnBu | RdYlBu_r' # 색상 Color map )
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(15, 10))
sns.heatmap(cor_df.corr()
, annot=True
, fmt='.1f'
, linewidth=0.5
, cmap='YlGnBu'
)
plt.show()
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(15, 10))
sns.heatmap(cor_df.corr()
, annot=True
, fmt='.1f'
, linewidth=0.5
, cmap='YlGnBu'
, vmin=-1
, vmax=1)
plt.show()
df.select_dtypes(include='int64').corr().sum().sort_values(ascending=False)
df.select_dtypes(include='int64').corr().sum().sort_values(ascending=False)[:8]
top8_cols = df.select_dtypes(include='int64').corr().sum().sort_values(ascending=False)[:8].index.tolist()
top8_cols
cor_df2 = df[top8_cols].corr()
sns.heatmap(cor_df2, annot=True, fmt='.1f', cmap='Blues')
# 삼각형 Mask 씌워서 Heatmap 깔끔하게 그려보기
import numpy as np
mask = np.zeros_like(cor_df2, dtype=bool)
mask[np.triu_indices_from(mask)] = True
sns.heatmap(cor_df2, annot=True, fmt='.1f', cmap='Blues', mask=mask)