How can I include labels in SNS heatmap?

237    Asked by ClareMatthews in Data Science , Asked on Feb 13, 2023

I got this matrix

120     100     80      40      20      10      5       0
120 64.21   58.20   51.20   56.37   47.00   45.61   46.86   2.16
100 62.84   57.80   50.60   51.32   39.43   39.30   42.80   0.89
80  62.62   56.20   51.20   51.61   46.23   37.20   42.20   5.32
40  62.05   52.10   44.20   48.79   42.22   35.16   41.80   1.81
20  61.65   50.90   42.30   46.23   44.83   32.70   41.50   6.24
10  59.69   50.20   40.10   40.20   44.28   32.80   39.90   12.31
5   59.05   49.20   40.60   38.90   44.10   30.80   32.80   9.91
0   56.20   49.10   40.50   38.60   36.20   32.20   31.50   0.00

I know how to plot heatmap for the values inside by specifying it as numpy array and then using

ax = sns.heatmap(nd, annot=True, fmt='g')

But can someone help me how to include the column and row labels? The column labels and row labels are given (120,100,80,42,etc.)
Answered by David EDWARDS
Here's how we can add simple X-Y labels in sns heatmap:

s = sns.heatmap(cm_train, annot=True, fmt='d', cmap='Blues')
s.set(xlabel='X-Axis', ylabel='Y-Axis')
OR
s.set_xlabel('X-Axis', fontsize=10)
s.set_ylabel('Y-Axis', fontsize=10)

Your Answer

Interviews

Parent Categories