Python Seaborn:仅减小 x 轴标签的大小

Python Seaborn: reducing the size of x-axis labels only

我正在尝试创建热图。我注意到由于尺寸太大,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轴标签的尺寸。谁能指导我如何解决这个问题?

  • 获取带有 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()