gpt4 book ai didi

Python pyplot x轴标签旋转

转载 作者:太空宇宙 更新时间:2023-11-04 00:35:15 27 4
gpt4 key购买 nike

我正在尝试旋转 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

最佳答案

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

关于Python pyplot x轴标签旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44338144/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com