0

I have the data frame h3_Ho_Hm which looks like this with hour as index.

        KE      EH          LA          PR
Hour                
15      0.01052 0.010545    0.010325    0.013201
30      0.01052 0.010545    0.010325    0.013201
45      0.01052 0.010545    0.010932    0.013201
100     0.01052 0.010545    0.010932    0.009901
115     0.01052 0.010545    0.010932    0.013201
------------------------------------------------
2245    0.01021 0.010252    0.010325    0.006601
2300    0.01021 0.010252    0.010021    0.009901
2315    0.01021 0.010252    0.010325    0.009901
2330    0.01021 0.010252    0.009718    0.009901
2345    0.01021 0.010252    0.010325    NaN

I want to create a heatmap which shows the columns on the y-axis and the hour column on the x-axis. I tried to use the code from this post which I implemented as so

Index = temp1[0] (a column with the hours)
Cols = ["KE", "EH", "LA", "PR"]
h3_heatmap = DataFrame(data = h3_Ho_Hm, index = Index, columns = Cols)

sns.heatmap(h3_heatmap)

Which give me this result

Heatmap

When I use the code below I get a nice result but still with the wrong axis order

sns.heatmap(h3_Ho_Hm)

Heatmap2

Any idea on how I can swap the axis so that the KE, EH, LA and PR are on the y-axis and the hours on the x-axis?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
MxGr20
  • 77
  • 6

1 Answers1

1

Use the transposed dataframe:

sns.heatmap(h3_Ho_Hm.T)
Arne
  • 9,990
  • 2
  • 18
  • 28
  • This works, thank you! I tried to transpose it as well with h3_Ho_Hm.transpose() but that didn't work. Glad your solution did work! – MxGr20 May 13 '21 at 15:41
  • I don't know why `h3_Ho_Hm.transpose()` didn't work. It should give the same result as `h3_Ho_Hm.T`. – Arne May 13 '21 at 18:00