简体   繁体   English

交换轴 Seaborn 热图 python

[英]Swap axis Seaborn heatmap python

I have the data frame h3_Ho_Hm which looks like this with hour as index.我有数据框 h3_Ho_Hm,它看起来像这样,以小时为索引。

        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.我想创建一个热图,显示 y 轴上的列和 x 轴上的小时列。 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这给了我这个结果

热图

When I use the code below I get a nice result but still with the wrong axis order当我使用下面的代码时,我得到了很好的结果,但轴顺序仍然错误

sns.heatmap(h3_Ho_Hm)

热图2

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?关于如何交换轴以使 KE、EH、LA 和 PR 位于 y 轴而小时位于 x 轴的任何想法?

Use the transposed dataframe:使用转置后的 dataframe:

sns.heatmap(h3_Ho_Hm.T)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM