Seaborn heatmap not displaying all xticks and yticks

Question:

I have a pandas dataframe of shape (39, 67). When I plot it’s seaborn heatmap, I don’t get as many labels on the X and Y axes. .get_xticklabels() method also returns only 23 labels.

Seaborn heatmap for dataframe

matplotlib doesn’t show any labels (only numbers) as well.

Matpllotlib heatmap

Both these heatmaps are for the same dataframe (39, 67).

Asked By: Skywalker

||

Answers:

To ensure the labels are visible, you have to set the parameters xticklabels, yticklabels to True, like so.

import seaborn as sns 
sns.heatmap(dataframe, xticklabels=True, yticklabels=True)

Here’s the documentation for the heatmap function.

Answered By: Haran Rajkumar
import seaborn as sns 
sns.heatmap(dataframe, xticklabels=1, yticklabels=1)

You may also play with figsize=(7, 5) to adjust the scale.

Answered By: Code42

The answers here didnt work for me so I followed the suggestions here.
Try opening a separate matplotlib window and tweak the parameters there,
Python sns heatmap does not fully display x labels

Answered By: Arunava Maulik
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.