【问题标题】:How to make the xlabels vertical and reduce the size of the colorbar in heatmap如何使 xlabels 垂直并减小热图中颜色条的大小
【发布时间】:2020-07-19 16:41:46
【问题描述】:

我有以下代码可以生成我的热图:

import seaborn as sns

fig1, ax1 = plt.subplots(figsize=(40,40))
ax1 = sns.heatmap(df_trans, 
                  cmap="RdBu", 
                  annot=True, 
                  cbar_kws={'label': scor},
                  square=True)
plt.show()

如何使 xlabels(即 x 轴上的标签)从当前水平变为垂直?

您还可以看到右侧的颜色条对于我的热图来说太大(太长)。如何减少颜色条的长度?

非常感谢。

【问题讨论】:

    标签: python seaborn heatmap colorbar


    【解决方案1】:

    ax1.set_xticklabels(ax1.get_xticklabels(), rotation=90)

    对于颜色条的大小,我没有示例可尝试,但您可以尝试添加 sns.seaborn cbar_kws={"shrink": 0.5}

    【讨论】:

    • 谢谢!使用cbar_kws,有两个像cbar_kws={'label': scor, 'shrink': 0.5} 这样的参数应该仍然有效吗?
    • 是的,我认为应该这样做,但我无法在我的代码中尝试。
    猜你喜欢
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 2021-11-07
    • 2015-12-09
    • 2012-10-07
    • 2017-10-31
    • 2013-10-24
    相关资源
    最近更新 更多