【问题标题】:Python Seaborn: reducing the size of x-axis labels only [duplicate]Python Seaborn:仅减小x轴标签的大小[重复]
【发布时间】:2020-05-20 22:57:41
【问题描述】:

我正在尝试创建热图。我注意到由于尺寸过大,x 轴标签没有完全显示。

我尝试使用以下命令减小 x 轴标签的大小:

ax = plt.axes()
sns.set(font_scale=0.8)
plt.rcParams["axes.labelsize"] = 0.5
sns.heatmap(equip_df.set_index('Zone'), annot=True,ax=ax)
ax.set_title('Year 2016')
plt.show()

但它并没有减小 x 轴标签的大小。谁能指导我如何解决这个问题?

【问题讨论】:

    标签: python python-3.x seaborn heatmap


    【解决方案1】:
    • 使用locs, labels = plt.xticks() 获取标签
    • b.set_xticklabels(labels, size = 4)设置字体
    import seaborn as sns
    import numpy as np
    import matplotlib.pyplot as plt
    
    flights = sns.load_dataset("flights")
    flights = flights.pivot("year", "month", "passengers")
    
    plt.figure(figsize=(6, 8))
    b = sns.heatmap(flights)
    
    # get the labels
    _, labels = plt.xticks()
    
    # set the label size
    b.set_xticklabels(labels, size = 4, rotation=90)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      • 2021-12-09
      相关资源
      最近更新 更多