-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatesetGet.py
More file actions
60 lines (50 loc) · 1.51 KB
/
Copy pathdatesetGet.py
File metadata and controls
60 lines (50 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.setrecursionlimit(1000000)
X_t = []
Y_t = []
current_lab = '0'
fig, ax = plt.subplots()
def on_mouse_click(event):
ax.clear()
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
print(event.xdata, event.ydata)
X_t.append([event.xdata, event.ydata])
if current_lab == '0':
Y_t.append([1, 0, 0, 0])
elif current_lab == '1':
Y_t.append([0, 1, 0, 0])
elif current_lab == '2':
Y_t.append([0, 0, 1, 0])
elif current_lab == '3':
Y_t.append([0, 0, 0, 1])
else:
print("error in current_lab")
for i in range(len(X_t)):
if Y_t[i][0] == 1:
ax.scatter(X_t[i][0], X_t[i][1], 20, 'r')
elif Y_t[i][1] == 1:
ax.scatter(X_t[i][0], X_t[i][1], 20, 'g')
elif Y_t[i][2] == 1:
ax.scatter(X_t[i][0], X_t[i][1], 20, 'y')
elif Y_t[i][3] == 1:
ax.scatter(X_t[i][0], X_t[i][1], 20, 'c')
plt.show()
def on_key_press(event):
print("Current lab is %s" % event.key)
global current_lab
current_lab = event.key
def get_points():
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
fig.canvas.mpl_connect('button_press_event', on_mouse_click)
fig.canvas.mpl_connect('key_press_event', on_key_press)
plt.show()
X = np.array(X_t).T
Y = np.array(Y_t).T
return [X, Y]
[x_data, y_data] = get_points()
np.savetxt("x_data.txt", x_data)
np.savetxt("y_data.txt", y_data)