Home > Software engineering >  Seaborn heatmap, how to specifiy x,y axes from data frame
Seaborn heatmap, how to specifiy x,y axes from data frame

Time:09-23

I have a data frame with three columns, two of them are positions x & y and the third one is an error. I would like to plot the error for each combination of (x,y) position combination on a heat map but I'm failing miserably.

I tired the following:

df_X['x_error']=df_X['x_error'].astype(float) 
p1 = sns.heatmap(df_X,annot=True)

Here's my data frame df_X:

index   y_position  x_position  x_error
0   2.0     106.0   0.28
1   2.0     107.0   2.15
2   2.0     114.0   2.24
3   2.0     115.0   4.38
4   2.0     122.0   6.33
5   2.0     123.0   8.54
6   2.0     130.0   11.41
7   2.0     131.0   12.60
8   3.0     100.0   5.53
9   3.0     101.0   7.58
10  3.0     108.0   2.97
11  3.0     109.0   4.52
12  3.0     116.0   3.14
13  3.0     117.0   3.27
14  3.0     124.0   5.66
15  3.0     125.0   10.27
16  3.0     132.0   10.17
17  3.0     133.0   12.93
18  3.0     140.0   5.09
19  3.0     141.0   5.08
20  4.0     95.0    10.21
21  4.0     96.0    14.66
22  4.0     103.0   4.52
23  4.0     104.0   6.58
24  4.0     111.0   2.92
25  4.0     112.0   5.59
26  4.0     119.0   3.34
27  4.0     120.0   5.14
28  4.0     127.0   10.59
29  4.0     128.0   12.98
30  4.0     135.0   8.13
31  4.0     136.0   9.25
32  4.0     143.0   3.25

Here's what I got:

enter image description here

Here's what I would like to have: enter image description here

Can anyone help me please ?

CodePudding user response:

Try this:

df_X = df_X.pivot("y_position", "x_position", "x_error")
ax = sns.heatmap(df_X)
  • Related