teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コメントを受けて回答を修正

2020/01/12 03:59

投稿

magichan
magichan

スコア15898

answer CHANGED
@@ -13,4 +13,32 @@
13
13
  ax.set_ylabel('Rate')
14
14
  plt.show()
15
15
  ```
16
- ![イメージ説明](26a5444f4ed26c1eaf54aefc33f4adea.png)
16
+ ![イメージ説明](26a5444f4ed26c1eaf54aefc33f4adea.png)
17
+
18
+ ---
19
+ **追記**
20
+
21
+ ```Python
22
+ import pandas as pd
23
+ import matplotlib.pyplot as plt
24
+
25
+ df = pd.DataFrame({'Sample No.':[1,2,3,4,5,6],
26
+ 'Black':[30,45,10,15,40,30],
27
+ 'Green': [20,30,60,40,45,45],
28
+ 'Red': [50,25,30,45,15,25]})
29
+ df['Pos'] = [0,1,3,4,6,7]
30
+
31
+ ax = plt.subplot()
32
+ ax.bar(x=df['Pos'], height=df['Red'], bottom=0, color='red', label='Red')
33
+ ax.bar(x=df['Pos'], height=df['Green'], bottom=df['Red'], color='green', label='Green')
34
+ ax.bar(x=df['Pos'], height=df['Black'], bottom=df['Red']+df['Green'], color='black', label='Black')
35
+
36
+ ax.set_xticks(df['Pos'])
37
+ ax.set_xticklabels(df['Sample No.'])
38
+ ax.set_xlabel('Sample No.')
39
+ ax.set_ylabel('Rate')
40
+ ax.legend()
41
+ plt.savefig('out2.png')
42
+ plt.show()
43
+ ```
44
+ ![イメージ説明](6bf4bf3d01c299d5780a44d775a39d82.png)