f, ax = plt.subplots(figsize=(8, 6))
sns.heatmap(df)
groups = df.index.get_level_values(0)
for i, group in enumerate(groups):
    if i and group != groups[i - 1]:
        ax.axhline(len(groups) - i, c='w', linewidth=3)
ax.axvline(1, c='w', linewidth=3)
f.tight_layout()
Divide seaborn matrix by lines according to clustering