def create_plotwindow(x=None, y=None): if x == None: x = SizedList(2000) if y == None: y = SizedList(2000) u_plotwindow = PlotWindow(None) u_plotwindow.SetTitle("Upload") u_plotwindow.SetBackgroundColour((255,255,255)) u_plotwindow.points = [x, y] u_plotwindow.Show() u_plotwindow.Bind(wx.EVT_SIZE, u_plotwindow.area_expose_cb) return u_plotwindow
def draw_points(self, area, a, b): if len(a) < 3: return x1 = a[-1] y1 = b[-1] w, h = area.GetSize() a, b, ma, mb = self.scale_points(a, b, w, h) c = zip(a, b) c = filter_points.remove_dupes(c) area.Clear() area.SetPen(wx.Pen((0,0,0))) area.DrawPoints(c) ## try: ## rc = c#random.sample(c, 1000) ## ra = [ x for x, y in rc ] ## rb = [ y for x, y in rc ] ## ## #a, b, c = matfunc.polyfit((ra, rb)) ## #lines = self.get_lines(w, a, b, c) ## #a, b, c, d = matfunc.polyfit((ra, rb), 3) ## a, b = matfunc.polyfit((ra, rb), 1) ## lines = self.get_lines1(w, a, b) ## area.DrawLines(lines) ## #area.draw_lines(area.gc, lines) ## except Exception, e:# ZeroDivisionError: ## print e ## pass u = SizedList(10) t = SizedList(10) points = [] for (x,y) in c: u.append(x) t.append(y) #x2 = float(sum(u)) / float(len(u)) x2 = x y2 = h - filter_points.standard_deviation(t) #y2 = float(sum(t)) / float(len(t)) points.append((x2,y2)) #area.draw_lines(area.gc, points) area.SetPen(wx.Pen((255,0,0))) area.DrawPoints(points) def avg_atan2_p(a, b): atan = 0 x = 0 y = 0 as = 0 t = float(len(a)) for p1, p2 in zip(a, b): atan += math.atan2(p1, p2) / t try: as += math.sqrt(p1**2 + p2**2) / t except ZeroDivisionError, e: print e
x = math.sin(atan) * as y = math.cos(atan) * as return x, y def median(a, b): a = list(a) a.sort() b = list(b) b.sort() ap = min(len(a)-1, 5) bp = min(len(b)-1, 5) return a[ap], b[bp] u = SizedList(10) t = SizedList(10) points = [] for (x,y) in c: u.append(x) t.append(y) x2, y2 = avg_atan2_p(u, t) #x2, y2 = median(u,t) #x2 = x #y2 = float(sum(t)) / float(len(t)) points.append((x2,y2)) #area.draw_lines(area.gc, points) area.SetPen(wx.Pen((0,0,255))) #area.DrawPoints(points)