質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -67,6 +67,78 @@
|
|
67
67
|
^
|
68
68
|
SyntaxError: invalid syntax
|
69
69
|
```
|
70
|
+
### 追記2 - 同じTypeであっても値は一定ではなくランダムに設定したい
|
71
|
+
|
72
|
+
```Python
|
73
|
+
import pandas as pd
|
74
|
+
import numpy as np
|
75
|
+
import matplotlib.pyplot as plt
|
76
|
+
import japanize_matplotlib
|
77
|
+
|
78
|
+
pd.options.display.float_format="{:.2f}".format
|
79
|
+
|
80
|
+
type = ["FF","CU","SP","SL","SI","CB"]
|
81
|
+
|
82
|
+
N = 1000
|
83
|
+
type = np.random.choice(type,size=N)
|
84
|
+
df = pd.DataFrame({"Type":type})
|
85
|
+
# Score1
|
86
|
+
df.loc[df.Type=="FF","Score1"] = np.random.rand()*10+150
|
87
|
+
df.loc[df.Type=="CU","Score1"] = np.random.rand()*10+140
|
88
|
+
df.loc[df.Type=="SP","Score1"] = np.random.rand()*10+130
|
89
|
+
df.loc[df.Type=="SL","Score1"] = np.random.rand()*10+120
|
90
|
+
df.loc[df.Type=="SI","Score1"] = np.random.rand()*10+145
|
91
|
+
df.loc[df.Type=="CB","Score1"] = np.random.rand()*20+100
|
92
|
+
# Score2
|
93
|
+
df.loc[df.Type=="FF","Score2"] = np.random.rand()*30+35
|
94
|
+
df.loc[df.Type=="CU","Score2"] = np.random.rand()*30+10
|
95
|
+
df.loc[df.Type=="SP","Score2"] = np.random.rand()*20+0
|
96
|
+
df.loc[df.Type=="SL","Score2"] = np.random.rand()*20-10
|
97
|
+
df.loc[df.Type=="SI","Score2"] = np.random.rand()*20+20
|
98
|
+
df.loc[df.Type=="CB","Score2"] = np.random.rand()*30-40
|
99
|
+
# Score3
|
100
|
+
df.loc[df.Type=="FF","Score3"] = np.random.rand()*30+15
|
101
|
+
df.loc[df.Type=="CU","Score3"] = np.random.rand()*30-10
|
102
|
+
df.loc[df.Type=="SP","Score3"] = np.random.rand()*30+10
|
103
|
+
df.loc[df.Type=="SL","Score3"] = np.random.rand()*40-30
|
104
|
+
df.loc[df.Type=="SI","Score3"] = np.random.rand()*20+30
|
105
|
+
df.loc[df.Type=="CB","Score3"] = np.random.rand()*10-25
|
106
|
+
|
107
|
+
#画像サイズ、軸サイズ調整
|
108
|
+
plt.figure(figsize=(11,11))
|
109
|
+
#各タイプの色を定義づけ
|
110
|
+
pitch_colors = {"FF":"b","SI":"c","SL":"r","SP":"g","CB":"pink","CU":"y"}
|
111
|
+
ax1 = plt.subplot(1,1,1)
|
112
|
+
|
113
|
+
# make ScatterPlot
|
114
|
+
ax1.axis([-70,70,-70,70])
|
115
|
+
x = df[["Score3"]]
|
116
|
+
y = df[["Score2"]]
|
117
|
+
#各タイプを色別でplot
|
118
|
+
for k in pitch_colors:
|
119
|
+
df_selected = df[df['Type'] == k]
|
120
|
+
if not df_selected.empty:
|
121
|
+
df_selected.plot.scatter(x='Score3', y='Score2', marker='o', c=pitch_colors[k], s = 50, label=k, ax=ax1)
|
122
|
+
#プロットのグリッド線
|
123
|
+
ax1.grid(True,linestyle = "dotted")
|
124
|
+
# adding vertical line in data co-ordinates
|
125
|
+
ax1.axvline(0, c='silver', ls='-')
|
126
|
+
# adding horizontal line in data co-ordinates
|
127
|
+
ax1.axhline(0, c='silver', ls='-')
|
128
|
+
#凡例の表示
|
129
|
+
flg=12
|
130
|
+
ax1.legend(loc='upper left',fontsize=flg,title='Type')
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
```
|
136
|
+
### 追記2 -現状と理想
|
137
|
+
現状
|
138
|
+

|
139
|
+
|
140
|
+
理想(ランダムで作成したものではないため例です)
|
141
|
+

|
70
142
|
|
71
143
|
### 補足情報(FW/ツールのバージョンなど)
|
72
144
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,6 +42,31 @@
|
|
42
42
|
|
43
43
|
|
44
44
|
```
|
45
|
+
### 追記(条件が3種以上の場合は?)
|
46
|
+
```Python
|
47
|
+
## ランダムデータの作成
|
48
|
+
import pandas as pd
|
49
|
+
import numpy as np
|
50
|
+
|
51
|
+
pd.options.display.float_format="{:.2f}".format
|
52
|
+
type = ["FF","SL","CU"]
|
53
|
+
N = 1000
|
54
|
+
type = np.random.choice(type,size=N)
|
55
|
+
df = pd.DataFrame({
|
56
|
+
"Pitch Type":type,
|
57
|
+
"Score1":[np.random.rand()*10+150 if t == "FF" elif np.random.rand()*20+130 if t == "SL" else np.random.rand()*10+140 for t in type],
|
58
|
+
"Score2":[np.random.rand()*40+30 if t == "FF" else np.random.rand()*20+30 for t in type],
|
59
|
+
"Score3":[np.random.rand()*20+20 if t == "FF" else np.random.rand()*30-10 for t in type],
|
60
|
+
})
|
61
|
+
|
62
|
+
```
|
63
|
+
### 追記(発生しているエラー)
|
64
|
+
```
|
65
|
+
File "C:\Users\DELL\AppData\Local\Temp/ipykernel_18992/3232225939.py", line 13
|
66
|
+
"Score1":[np.random.rand()*10+150 if t == "FF" elif np.random.rand()*20+130 if t == "SL" else np.random.rand()*10+140 for t in type],
|
67
|
+
^
|
68
|
+
SyntaxError: invalid syntax
|
69
|
+
```
|
45
70
|
|
46
71
|
### 補足情報(FW/ツールのバージョンなど)
|
47
72
|
|