-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPoints.ipy
More file actions
80 lines (73 loc) · 2.3 KB
/
Copy pathgetPoints.ipy
File metadata and controls
80 lines (73 loc) · 2.3 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# getPoints.ipy
#
# usage: getPoints.ipy
# by: justin gardner
# date: 10/30/15
# purpose: To get points that a user has clicked on for classification tutorial
#
##########
# import #
##########
import matplotlib.pyplot as pyplot
import numpy as np
# start matplotlib
%matplotlib nbagg
######################
# makeInstances #
######################
class makeInstances:
# class initializer
def __init__(self, pyplot):
# keep pyplot
self.pyplot = pyplot
# setup figure
self.f = pyplot.figure()
self.a = self.f.add_subplot(111)
pyplot.axis('off')
# set axis
pyplot.xlim(0,1)
pyplot.ylim(0,1)
self.a.set_title('Click points in first group then double-click.')
# initialize list of points
self.x1 = []
self.x2 = []
# variable to keep which list we are working on
self.listNum = 1
# set callback for button presses
self.cid = self.f.canvas.mpl_connect('button_press_event', self)
# button press callback
def __call__(self, event):
if event.dblclick:
if self.listNum == 1:
self.listNum = 2
else:
self.pyplot.close()
# convert to numpy arrays which
self.x1 = np.array(self.x1)
self.x2 = np.array(self.x2)
else:
# check if event is on axis
if event.inaxes!=self.a: return
# log x, y corridnates
if self.listNum == 1:
# keep points in first list
self.x1.append([event.xdata,event.ydata])
# and plot them
self.pyplot.plot(event.xdata,event.ydata,'ro')
else:
# keep points in first list
self.x2.append([event.xdata,event.ydata])
# and plot them
self.pyplot.plot(event.xdata,event.ydata,'bo')
# setup calback to makeInstances
instances = makeInstances(pyplot)
def dispInstances(instances):
# setup figure
f = pyplot.figure()
a = f.add_subplot(111)
pyplot.axis('off')
# set axis
pyplot.xlim(0,1)
pyplot.ylim(0,1)
pyplot.plot(instances.x1[:,0],instances.x1[:,1],'ro')
pyplot.plot(instances.x2[:,0],instances.x2[:,1],'bo')