【发布时间】:2018-04-24 09:34:34
【问题描述】:
我试图通过 seaborn 绘制一个混淆矩阵,但当 yticklabels 旋转到 90 度时无法居中对齐它们。虽然 ha 可以在没有旋转的情况下工作,但会因旋转而失败。这是最小的工作示例 -
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')
任何帮助将不胜感激。
【问题讨论】:
-
尝试添加
rotation_mode='anchor' -
完美!那行得通!感谢您的及时回复。
-
你们中的某个人会发布一个答案,这样这个问题就会被关闭吗?
标签: python matplotlib plot alignment seaborn