回答編集履歴
1
追記
answer
CHANGED
@@ -42,4 +42,60 @@
|
|
42
42
|
```
|
43
43
|
|
44
44
|
**result.png**
|
45
|
-

|
45
|
+

|
46
|
+
|
47
|
+
|
48
|
+
### 追記
|
49
|
+
上と同様にpandasでやろうとした・・・らなかなか思い通りにplotできなかったので、生matplotlibで書いてみたコード。コードの見た目はともかく、結果はこんな感じで良いでしょうか。
|
50
|
+
|
51
|
+
```python
|
52
|
+
import io
|
53
|
+
import pandas as pd
|
54
|
+
import matplotlib.pyplot as plt
|
55
|
+
|
56
|
+
txt = """
|
57
|
+
出力 制御A 制御B 制御C
|
58
|
+
100 2 8 1
|
59
|
+
100 2 5 1
|
60
|
+
150 3 4 9
|
61
|
+
150 3 5 6
|
62
|
+
200 5 2 7
|
63
|
+
200 5 2 7
|
64
|
+
170 2 8 1
|
65
|
+
170 2 8 1
|
66
|
+
80 2 8 9
|
67
|
+
"""
|
68
|
+
|
69
|
+
df = pd.read_table(io.StringIO(txt), delimiter="\t", header=0)
|
70
|
+
print(df)
|
71
|
+
""" =>
|
72
|
+
出力 制御A 制御B 制御C
|
73
|
+
0 100 2 8 1
|
74
|
+
1 100 2 5 1
|
75
|
+
2 150 3 4 9
|
76
|
+
3 150 3 5 6
|
77
|
+
4 200 5 2 7
|
78
|
+
5 200 5 2 7
|
79
|
+
6 170 2 8 1
|
80
|
+
7 170 2 8 1
|
81
|
+
8 80 2 8 9
|
82
|
+
"""
|
83
|
+
|
84
|
+
df["メイン制御"] = df.apply(lambda s: s.idxmin(), axis=1)
|
85
|
+
|
86
|
+
c_dict = {"制御A":"b", "制御B":"y", "制御C":"r"}
|
87
|
+
|
88
|
+
plt.figure()
|
89
|
+
for label in ["制御A","制御B","制御C"]:
|
90
|
+
tmp = df[df["メイン制御"]==label]
|
91
|
+
plt.bar(tmp.index, tmp["出力"],
|
92
|
+
color=c_dict[label],
|
93
|
+
label=label,
|
94
|
+
align="center")
|
95
|
+
plt.xticks(df.index)
|
96
|
+
plt.legend()
|
97
|
+
plt.savefig("result2.png")
|
98
|
+
```
|
99
|
+
|
100
|
+
**result2.png**
|
101
|
+

|