2016-08-18 6 views

답변

2

나는 약간의 시간을 할애했다. 기본적으로 매트릭스의 절반을 덮기 위해 마스크를 사용하는 두 개의 히트 맵을 중첩해야한다. 아래에 코드 예제가 나와 있습니다.

import numpy as np 
import pandas as pd 
import seaborn 
from matplotlib.colors import ListedColormap 
from matplotlib.pylab import * 

arr_name = ['D','S','P','E','C','KW','K','EF'] 
data = np.random.randn(8,8) 
df = pd.DataFrame(data, columns=arr_name) 
labels = df.where(np.triu(np.ones(df.shape)).astype(np.bool)) 
labels = labels.round(2) 
labels = labels.replace(np.nan,' ', regex=True) 

mask = np.triu(np.ones(df.shape)).astype(np.bool) 
ax = seaborn.heatmap(df, mask=mask, cmap='RdYlGn_r', fmt='', square=True, linewidths=1.5) 
mask = np.ones((8, 8))-mask 
ax = seaborn.heatmap(df, mask=mask, cmap=ListedColormap(['white']),annot=labels,cbar=False, fmt='', linewidths=1.5) 
ax.set_xticks([]) 
ax.set_yticks([]) 
plt.show() 

최종 결과는 다음된다 enter image description here