簡體   English   中英

Seaborn kde plot 錯誤:無法使用寬格式數據“hue”分配以下變量

[英]Seaborn error with kde plot: The following variable cannot be assigned with wide-form data `hue`

我有一個 pandas dataframe df有兩列( typeIR )作為這個:

   type    IR
0   a      0.1
1   b      0.3
2   b      0.2
3   c      0.8
4   c      0.5
      ...

我想要 plot 三個分布(每個type一個)與 IR 的值所以,我寫:

sns.displot(df, kind="kde", hue='type', rug=True)

但我收到此錯誤: The following variable cannot be assigned with wide-form data 'hue'

任何的想法?


編輯:

我真正的 dataframe 看起來像

pd.DataFrame({"type": ["IR orig", "IR orig", "IR orig", "IR trans", "IR trans", "IR trans", "IR perm", "IR perm", "IR perm", "IR perm", "IR perm"],
              "IR": [1.41, 1.42, 1.32, 0.0, 0.44, 0.0, 1.41, 1.31, 1.41, 1.37, 1.34]
})

但是使用sns.displot(df, x='IR', kind="kde", hue='type', rug=True)我得到了ValueError: cannot reindex on an axis with duplicate labels

利用:

df = pd.DataFrame({'type': {0: 'a', 1: 'b', 2: 'b', 3: 'c', 4: 'c'}, 
                   'IR': {0: 0.1, 1: 0.3, 2: 0.2, 3: 0.8, 4: 0.5}})
print (df)
  type   IR
0    a  0.1
1    b  0.3
2    b  0.2
3    c  0.8
4    c  0.5

sns.displot(df.reset_index(drop=True), x='IR', kind="kde", hue='type', rug=True)

圖片

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM