def _on_custom(self, evt): # add some text to the axes in a random location in axes (0,1) # coords) with a random color # get the axes ax = self.canvas.figure.axes[0] # generate a random location can color x, y = tuple(rand(2)) rgb = tuple(rand(3)) # add the text and draw ax.text(x, y, 'You clicked me', transform=ax.transAxes, color=rgb) self.canvas.draw() evt.Skip()
def _on_custom(self, evt): # add some text to the axes in a random location in axes (0,1) # coords) with a random color # get the axes ax = self.canvas.figure.axes[0] # generate a random location can color x,y = tuple(rand(2)) rgb = tuple(rand(3)) # add the text and draw ax.text(x, y, 'You clicked me', transform=ax.transAxes, color=rgb) self.canvas.draw() evt.Skip()
def rand_point(): xy = rand(2) return Point( Value(xy[0]), Value(xy[1]) )
a = multiply_affines(a2, a1) assert( a1.xy_tup(pnt) == (6,8) ) assert( a.xy_tup(pnt) == (8,17) ) # change num to 4 and make sure the affine product is still right num.set(4) assert( a1.xy_tup(pnt) == (12,16) ) assert( a.xy_tup(pnt) == (16,65) ) # test affines with arithemtic sums of lazy values val = num*(one + two) a1 = Affine(one, zero, zero, val, num, val) assert(a1.xy_tup(pnt) == (7, 60)) x = rand(20) y = rand(20) transform = identity_transform() xout, yout = transform.seq_x_y(x,y) assert((x,y) == transform.seq_x_y(x,y)) # test bbox transforms; transform the unit coordinate system to # "display coords" bboxin = unit_bbox() ll = Point( Value(10), Value(10) ) ur = Point( Value(200), Value(40) ) bboxout = Bbox(ll, ur) transform = get_bbox_transform(bboxin, bboxout)
def rand_point(): xy = rand(2) return Point(Value(xy[0]), Value(xy[1]))
a = multiply_affines(a2, a1) assert (a1.xy_tup(pnt) == (6, 8)) assert (a.xy_tup(pnt) == (8, 17)) # change num to 4 and make sure the affine product is still right num.set(4) assert (a1.xy_tup(pnt) == (12, 16)) assert (a.xy_tup(pnt) == (16, 65)) # test affines with arithemtic sums of lazy values val = num * (one + two) a1 = Affine(one, zero, zero, val, num, val) assert (a1.xy_tup(pnt) == (7, 60)) x = rand(20) y = rand(20) transform = identity_transform() xout, yout = transform.seq_x_y(x, y) assert ((x, y) == transform.seq_x_y(x, y)) # test bbox transforms; transform the unit coordinate system to # "display coords" bboxin = unit_bbox() ll = Point(Value(10), Value(10)) ur = Point(Value(200), Value(40)) bboxout = Bbox(ll, ur) transform = get_bbox_transform(bboxin, bboxout) assert (transform.xy_tup((0, 0)) == (10, 10))
def rand_transform(): b1 = rand_bbox() b2 = rand_bbox() return get_bbox_transform(b1, b2) class Line: def __init__(self): self._transform = identity_transform() def set_transform(self, t): self._transform = t x, y = rand(2, 10000) indStart, indEnd = 30, 350 for i in range(indEnd): for j in range(20): l = Line() t1 = rand_transform() t2 = rand_transform() trans = blend_xy_sep_transform(t1, t2) l.set_transform(trans) xt, yt = trans.numerix_x_y(x, y) xytup = tuple(rand(2)) txytup = trans.xy_tup(xytup) ixytup = trans.inverse_xy_tup(xytup) seqt = trans.seq_xy_tups(zip(x, y)) gc.collect() val = report_memory(i)
def rand_transform(): b1 = rand_bbox() b2 = rand_bbox() return get_bbox_transform(b1, b2) class Line: def __init__(self): self._transform = identity_transform() def set_transform(self, t): self._transform = t x, y = rand(2,10000) indStart, indEnd = 30, 350 for i in range(indEnd): for j in range(20): l = Line() t1 = rand_transform() t2 = rand_transform() trans = blend_xy_sep_transform( t1, t2) l.set_transform(trans) xt, yt = trans.numerix_x_y(x, y) xytup = tuple(rand(2)) txytup = trans.xy_tup(xytup) ixytup = trans.inverse_xy_tup(xytup) seqt = trans.seq_xy_tups(zip(x,y)) gc.collect() val = report_memory(i)
def rand_val(N=1): if N == 1: return Value(rand()) else: return [Value(val) for val in rand(N)]
def report_memory(i): pid = os.getpid() if sys.platform == 'sunos5': command = 'ps -p %d -o rss,osz' % pid else: 'ps -p %d -o rss,sz' % pid a2 = os.popen(command).readlines() print i, ' ', a2[1], return int(a2[1].split()[1]) N = 200 for i in range(N): v1, v2, v3, v4, v5 = rand_val(5) b1 = v1 + v2 b2 = v3 - v4 b3 = v1 * v2 * b2 - b1 p1 = rand_point() box1 = rand_bbox() t = rand_transform() N = 10000 x, y = rand(N), rand(N) xt, yt = t.numerix_x_y(x, y) xys = t.seq_xy_tups(zip(x, y)) val = report_memory(i) if i == 1: start = val end = val print 'Average memory consumed per loop: %1.4f\n' % ((end - start) / float(N))
def rand_val(N = 1): if N==1: return Value(rand()) else: return [Value(val) for val in rand(N)]
if sys.platform=='sunos5': command = 'ps -p %d -o rss,osz' % pid else: 'ps -p %d -o rss,sz' % pid a2 = os.popen(command).readlines() print i, ' ', a2[1], return int(a2[1].split()[1]) N = 200 for i in range(N): v1, v2, v3, v4, v5 = rand_val(5) b1 = v1 + v2 b2 = v3 -v4 b3 = v1*v2*b2 - b1 p1 = rand_point() box1 = rand_bbox() t = rand_transform() N = 10000 x, y = rand(N), rand(N) xt, yt = t.numerix_x_y(x, y) xys = t.seq_xy_tups( zip(x,y) ) val = report_memory(i) if i==1: start = val end = val print 'Average memory consumed per loop: %1.4f\n' % ((end-start)/float(N))