0

I am trying to create a heatmap. I noticed that x-axis label does not show completely due to large size.

enter image description here I tried to reduce the size of the x-axis label by using following commands:

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

But it did not reduce the size of x-axis label. Could anyone guide me how to fix the issue?

user2293224
  • 2,128
  • 5
  • 28
  • 52

1 Answers1

1
  • Get the labels with locs, labels = plt.xticks()
  • Set the font with 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()

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158