简体   繁体   English

Python pyplot X轴标签旋转

[英]Python pyplot x-axis label rotation

I am trying to rotate the xaxis labels but the xticks function below has no effect and the labels overwrite each other 我正在尝试旋转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()

X轴混乱

After using suggested code changes: I get the following but I still want to increase the size of the heatmap 使用建议的代码更改后:我得到以下信息,但我仍然想增加热图的大小

如何增加此热图的大小

setp looks to be the way to go with pyplot (inspiration from this answer ). setp似乎是使用pyplot的方法(此答案的启发)。 This works for me: 这对我有用:

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()

Obviously I don't have your data, hence the numpy random data, but otherwise the effect is as required: 显然,我没有您的数据,因此没有numpy随机数据,但其他效果是必需的:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM