How to align xlabels and ylabels in seaborn? [dupl

2019-08-05 15:43发布

This question already has an answer here:

I am plotting heatmap of features but the feature names on x and y axes conincide with each other. So how can I align x axis feature names vertically and y axis feature names horizontally so that they do not overlap.

Code:

%matplotlib notebook
corr = data.loc[:,'PERID':'PRXRETRY'].corr()

sns.set(font_scale=0.8)
sns.heatmap(corr, 
            xticklabels=corr.columns.values,
            yticklabels=corr.columns.values,cmap="YlGnBu",annot=True)

Screenshot:

enter image description here

1条回答
爷的心禁止访问
2楼-- · 2019-08-05 16:27

This works for me:

hm = sns.heatmap(corr, cmap="YlGnBu", annot=True)
hm.set_xticklabels(labels=corr.columns.values, rotation=90)
hm.set_yticklabels(labels=corr.columns.values, rotation=0)
查看更多
登录 后发表回答