1

I'm using seaborn to draw a heatmap. But if there are too many yticks, some of them will be automatically hidden. The result looks like:
heatmap

As you can see, the yticks only shows 1, 3, 5, 7.... 31, 33 How can I let seaborn or matplotlib show all of them like: 1, 2, 3, 4.....31, 32, 33, 34 ?

my code is:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

y = np.random.randint(1, 100, 510)
y = y.reshape((34,15))
df = pd.DataFrame(y, columns=[x for x in 'wwwwwwwwwwwwwww'], index=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34'])
sns.heatmap(df, annot=True)
plt.yticks(rotation=0)
plt.show()
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
sunnwmy
  • 143
  • 2
  • 9

1 Answers1

2

Seaborn heatmap provides arguments

xticklabels, yticklabels : “auto”, bool, list-like, or int, optional
If True, plot the column names of the dataframe. If False, don’t plot the column names. If list-like, plot these alternate labels as the xticklabels. If an integer, use the column names but plot only every n label. If “auto”, try to densely plot non-overlapping labels.

Hence the easies solution is to add yticklabels=1 as argument.

sns.heatmap(df, annot=True, yticklabels=1)

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712