回答編集履歴
2
Update
test
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
```python
|
2
2
|
|
3
3
|
import numpy as np
|
4
|
+
|
5
|
+
from numpy.lib.recfunctions import append_fields
|
4
6
|
|
5
7
|
import matplotlib.pyplot as plt
|
6
8
|
|
@@ -22,15 +24,25 @@
|
|
22
24
|
|
23
25
|
csv_files = ['a.csv', 'b.csv', 'c.csv']
|
24
26
|
|
27
|
+
colors = ['r', 'b', 'g']
|
28
|
+
|
25
29
|
data_set = []
|
26
30
|
|
27
|
-
for fname in csv_files:
|
31
|
+
for i, fname in enumerate(csv_files):
|
28
32
|
|
29
|
-
|
33
|
+
contents = np.genfromtxt(
|
30
34
|
|
31
|
-
n
|
35
|
+
fname=fname, names=True, dtype=None, delimiter=',')
|
32
36
|
|
37
|
+
contents = append_fields(
|
38
|
+
|
39
|
+
contents, 'name', [fname.split('.')[0]]*len(contents), usemask=False)
|
40
|
+
|
41
|
+
contents = append_fields(
|
42
|
+
|
33
|
-
|
43
|
+
contents, 'color', [colors[i]]*len(contents), usemask=False)
|
44
|
+
|
45
|
+
data_set.append(contents)
|
34
46
|
|
35
47
|
|
36
48
|
|
@@ -38,19 +50,19 @@
|
|
38
50
|
|
39
51
|
for num, name in names:
|
40
52
|
|
41
|
-
data = np.concatenate(
|
42
|
-
|
43
|
-
[d[d['num'] == num]
|
53
|
+
data = np.concatenate([d[d['num'] == num] for d in data_set])
|
44
54
|
|
45
55
|
plt.figure(figsize=(8, 8))
|
46
56
|
|
57
|
+
for d in data:
|
58
|
+
|
47
|
-
plt.scatter(d
|
59
|
+
plt.scatter(d['data1'], d['data2'], c=d['color'], label=d['name'])
|
48
60
|
|
49
61
|
plt.title(name); plt.xlabel(name); plt.ylabel(name)
|
50
62
|
|
51
63
|
plt.xlim(0,10); plt.ylim(0,10)
|
52
64
|
|
53
|
-
plt.grid()
|
65
|
+
plt.grid(); plt.legend()
|
54
66
|
|
55
67
|
plt.savefig(f'{num}_{name}.png')
|
56
68
|
|
@@ -62,4 +74,4 @@
|
|
62
74
|
|
63
75
|
|
64
76
|
|
65
|
-
![c
|
77
|
+
![scatter](3c02af2fedd79c939e8f89340ad39196.png)
|
1
Update
test
CHANGED
@@ -36,19 +36,11 @@
|
|
36
36
|
|
37
37
|
# plot data
|
38
38
|
|
39
|
-
|
39
|
+
for num, name in names:
|
40
40
|
|
41
|
-
|
41
|
+
data = np.concatenate(
|
42
42
|
|
43
|
-
|
43
|
+
[d[d['num'] == num][['data1', 'data2']] for d in data_set])
|
44
|
-
|
45
|
-
for num, name in names]
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# plotting
|
50
|
-
|
51
|
-
for num, name, data in plot_data:
|
52
44
|
|
53
45
|
plt.figure(figsize=(8, 8))
|
54
46
|
|