Python pyplot x轴标签旋转

时间:2017-06-02 22:13:13

标签: python matplotlib axis-labels

我正在尝试旋转xaxis标签,但下面的xticks功能无效,标签会互相覆盖

import matplotlib.pyplot as plt
import seaborn as sns
     corrmat = X.corr()
     plt.xticks(rotation=90)       
     plt.figure(figsize=(15,16))          
     ax = sns.heatmap(corrmat, vmin=0, vmax=1)
     ax.xaxis.tick_top()

Jumbled xaxis

使用建议的代码更改后:我得到以下内容,但我仍想增加热图的大小

How to increase the size of this heatmap

1 个答案:

答案 0 :(得分:3)

setp看起来像pyplot一样(灵感来自这个answer)。这对我有用:

import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import numpy as np; np.random.seed(0)

data = np.random.rand(10, 12)
ax = sns.heatmap(data)
ax.xaxis.tick_top()
locs, labels = plt.xticks()
plt.setp(labels, rotation=90)
plt.show()

显然,我没有你的数据,因此是numpy随机数据,但除此之外效果是必要的:

enter image description here

相关问题