-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLineBuilder.py
40 lines (38 loc) · 1.71 KB
/
LineBuilder.py
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
import matplotlib.pyplot as plt
from matplotlib import path
import scipy.interpolate as interpolate
from numpy import *
class LineBuilder:
def __init__(self, line,ax):
self.line = line
self.ax = ax
self.xs = []
self.ys = []
self.nodes = []
self.cid = line.figure.canvas.mpl_connect('button_press_event', self)
self.counter = 0
self.precision = 0.02
def __call__(self, event):
if event.inaxes != self.line.axes: return
if self.counter == 0:
self.xs.append(event.xdata)
self.ys.append(event.ydata)
self.nodes.append((event.xdata, event.ydata))
if abs(event.xdata-self.xs[0]) <= self.precision and abs(event.ydata-self.ys[0]) <= self.precision and self.counter != 0:
self.xs.append(self.xs[0])
self.ys.append(self.ys[0])
self.nodes.append((self.xs[0], self.ys[0]))
self.ax.scatter(self.xs,self.ys, s=30, edgecolor='black', linewidth=0, facecolor='black')
self.ax.scatter(self.xs[0], self.ys[0], s=30, edgecolor='black', linewidth=1, facecolor='red')
self.ax.plot(self.xs, self.ys, color= 'black')
self.line.figure.canvas.draw()
self.counter = 0
else:
if self.counter != 0:
self.xs.append(event.xdata)
self.ys.append(event.ydata)
self.nodes.append((event.xdata, event.ydata))
self.ax.scatter(self.xs, self.ys, s=30, edgecolor='black', linewidth=1, facecolor='gray')
self.ax.plot(self.xs, self.ys, color='black')
self.line.figure.canvas.draw()
self.counter = self.counter + 1