2016-08-18 12 views

答えて

2

私はそれをするのに少し時間を費やしましたが、基本的に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