回答編集履歴

2

追記

2021/07/25 16:14

投稿

meg_
meg_

スコア10903

test CHANGED
@@ -29,3 +29,35 @@
29
29
  ```
30
30
 
31
31
  ![イメージ説明](b63bad0ca068a67032f17c926ce7ab65.png)
32
+
33
+
34
+
35
+ ---
36
+
37
+ 【追記】
38
+
39
+ matplotlibを使って下記の様な感じでしょうか?
40
+
41
+ ```python
42
+
43
+ df = pd.DataFrame({'label':['A','a','B','b','C','D','e'],'case':['u','l','u','l','u','u','l'],'score':[134,102,82,112,104,94,122]})
44
+
45
+
46
+
47
+ for i in range(len(df)):
48
+
49
+ if df.loc[i, 'case'] == 'u':
50
+
51
+ plt.barh(df.loc[i, 'label'], df.loc[i, 'score'], color='b')
52
+
53
+ else:
54
+
55
+ plt.barh(df.loc[i, 'label'], df.loc[i, 'score'], color='g')
56
+
57
+ plt.legend(['u', 'l'])
58
+
59
+ plt.show()
60
+
61
+ ```
62
+
63
+ ![イメージ説明](6ff386fdc7f1f4c84697b76544d19645.png)

1

追記

2021/07/25 16:14

投稿

meg_
meg_

スコア10903

test CHANGED
@@ -15,3 +15,17 @@
15
15
 
16
16
 
17
17
  質問のコードでは見えませんが(データが0なので)各々AとBのバーが存在しているのではないでしょうか?
18
+
19
+
20
+
21
+ 上記コードでlabel=Aでcountry=Cがない場合は下記グラフとなります。
22
+
23
+ ```python
24
+
25
+ df = pd.DataFrame({'label': ['A', 'A', 'A', 'A', 'A', 'B', 'B','B', 'B', 'B'], 'score': [1, 1, 1, 2, 3, 1, 2, 3, 4, 5], 'country':['D', 'D', 'D', 'E', 'D', 'C', 'C','D', 'E', 'C']})
26
+
27
+ ax = sns.barplot(x='score', y='label', orient='h', data=df , hue='country', palette=sns.color_palette("Set2"))
28
+
29
+ ```
30
+
31
+ ![イメージ説明](b63bad0ca068a67032f17c926ce7ab65.png)