2017-11-11 205 views
0

我想通過seaborn繪製一個混淆矩陣,但當它們旋轉到90度時無法將yticklabels居中對齊。雖然 ha工作沒有旋轉,但旋轉失敗。這裏是最小的工作示例 -如何居中對齊seaborn中旋轉的yticklabels?

import numpy as np 
import seaborn as sns 
import matplotlib.pyplot as plt 

cmat = np.matrix([[2, 3], [4, 5]]) 
fig, ax = plt.subplots(figsize=(4, 4)) 

sns.heatmap(cm_greina, annot=True, xticklabels=['Faulty', 'Healthy'], cbar=False, ax=ax) 
ax.set_yticklabels(['Faulty', 'Healthy'], rotation=90, ha='center') 

任何幫助將不勝感激。

+1

嘗試加入'rotation_mode ='anchor'' –

+0

完美!這工作!感謝您的及時迴應。 –

+0

你們中的一個人會發佈一個答案,所以這個問題被關閉了嗎? –

回答

1

而是水平排列的,你可能想使用垂直對齊方式:

import numpy as np 
import seaborn as sns 
import matplotlib.pyplot as plt 

cmat = np.matrix([[2, 3], [4, 5]]) 
fig, ax = plt.subplots(figsize=(4, 4)) 

sns.heatmap(cmat, annot=True, xticklabels=['Faulty', 'Healthy'], cbar=False, ax=ax) 
ax.set_yticklabels(['Faulty', 'Healthy'], va='center', rotation = 90, position=(0,0.28)) 
plt.show()