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 make_fig(): """ make a figure No need to close figures or clean up since the objects will be destroyed when they go out of scope """ fig = Figure() #ax = fig.add_subplot(111) # add a standard subplot # add an axes at left, bottom, width, height; by making the bottom # at 0.3, we save some extra room for tick labels ax = fig.add_axes([0.2, 0.3, 0.7, 0.6]) line, = ax.plot([1, 2, 3], 'ro--', markersize=12, markerfacecolor='g') # make a translucent scatter collection x = nx.rand(100) y = nx.rand(100) area = nx.pi * (10 * nx.rand(100))**2 # 0 to 10 point radiuses c = ax.scatter(x, y, area) c.set_alpha(0.5) # add some text decoration ax.set_title('My first image') ax.set_ylabel('Some numbers') ax.set_xticks((.2, .4, .6, .8)) labels = ax.set_xticklabels(('Bill', 'Fred', 'Ted', 'Ed')) # To set object properties, you can either iterate over the # objects manually, or define you own set command, as in setapi # above. #setapi(labels, rotation=45, fontsize=12) for l in labels: l.set_rotation(45) l.set_fontsize(12) canvas = FigureCanvasAgg(fig) canvas.print_figure('webapp.png', dpi=150)
def make_fig(): """ make a figure No need to close figures or clean up since the objects will be destroyed when they go out of scope """ fig = Figure() #ax = fig.add_subplot(111) # add a standard subplot # add an axes at left, bottom, width, height; by making the bottom # at 0.3, we save some extra room for tick labels ax = fig.add_axes([0.2, 0.3, 0.7, 0.6]) line, = ax.plot([1,2,3], 'ro--', markersize=12, markerfacecolor='g') # make a translucent scatter collection x = nx.rand(100) y = nx.rand(100) area = nx.pi*(10 * nx.rand(100))**2 # 0 to 10 point radiuses c = ax.scatter(x,y,area) c.set_alpha(0.5) # add some text decoration ax.set_title('My first image') ax.set_ylabel('Some numbers') ax.set_xticks( (.2,.4,.6,.8) ) labels = ax.set_xticklabels(('Bill', 'Fred', 'Ted', 'Ed')) # To set object properties, you can either iterate over the # objects manually, or define you own set command, as in setapi # above. #setapi(labels, rotation=45, fontsize=12) for l in labels: l.set_rotation(45) l.set_fontsize(12) canvas = FigureCanvasAgg(fig) canvas.print_figure('webapp.png', dpi=150)
def rand_point(): xy = rand(2) return Point( Value(xy[0]), Value(xy[1]) )
from helpers import rand_val, rand_point, rand_bbox, rand_transform from matplotlib.numerix import rand def report_memory(i): pid = os.getpid() a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() print i, ' ', a2[1], return int(a2[1].split()[0]) 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))
pid = os.getpid() a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() print i, ' ', a2[1], return int(a2[1].split()[0]) fname = '/usr/local/share/matplotlib/Vera.ttf' N = 200 for i in range(N): gc = GraphicsContextBase() gc.set_clip_rectangle([20, 20, 20, 20]) o = RendererAgg(400, 400, 72) for j in range(50): xs = [400 * int(rand()) for k in range(8)] ys = [400 * int(rand()) for k in range(8)] rgb = (1, 0, 0) pnts = zip(xs, ys) o.draw_polygon(gc, rgb, pnts) o.draw_polygon(gc, None, pnts) for j in range(50): x = [400 * int(rand()) for k in range(4)] y = [400 * int(rand()) for k in range(4)] o.draw_lines(gc, x, y) for j in range(50): args = [400 * int(rand()) for k in range(4)] rgb = (1, 0, 0) o.draw_rectangle(gc, rgb, *args)
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_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() a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() print i, ' ', a2[1], return int(a2[1].split()[0]) fname = '/usr/local/share/matplotlib/Vera.ttf' N = 200 for i in range(N): gc = GraphicsContextBase() gc.set_clip_rectangle( [20,20,20,20] ) o = RendererAgg(400,400, 72) for j in range(50): xs = [400*int(rand()) for k in range(8)] ys = [400*int(rand()) for k in range(8)] rgb = (1,0,0) pnts = zip(xs, ys) o.draw_polygon(gc, rgb, pnts) o.draw_polygon(gc, None, pnts) for j in range(50): x = [400*int(rand()) for k in range(4)] y = [400*int(rand()) for k in range(4)] o.draw_lines( gc, x, y) for j in range(50): args = [400*int(rand()) for k in range(4)] rgb = (1,0,0) o.draw_rectangle(gc, rgb, *args)
def rand_point(): xy = rand(2) return Point(Value(xy[0]), Value(xy[1]))
from helpers import rand_val, rand_point, rand_bbox, rand_transform from matplotlib.numerix import rand def report_memory(i): pid = os.getpid() a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() print i, ' ', a2[1], return int(a2[1].split()[0]) 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))
class DataManager(gtk.Window): numRows, numCols = 20, 10 data = rand(numRows, numCols) def __init__(self): gtk.Window.__init__(self) self.connect('destroy', lambda win: gtk.main_quit()) self.set_title('GtkListStore demo') self.set_border_width(8) vbox = gtk.VBox(FALSE, 8) self.add(vbox) label = gtk.Label('Double click a row to plot the data') vbox.pack_start(label, FALSE, FALSE) sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) vbox.pack_start(sw, True, True) model = self.create_model() self.treeview = gtk.TreeView(model) self.treeview.set_rules_hint(TRUE) # matplotlib stuff fig = Figure(figsize=(6, 4)) self.canvas = FigureCanvas(fig) # a gtk.DrawingArea self.canvas.show() vbox.pack_start(self.canvas, False, False) ax = fig.add_subplot(111) self.line, = ax.plot(self.data[0, :], 'go') # plot the first row self.treeview.connect('row-activated', self.plot_row) sw.add(self.treeview) self.add_columns() self.set_default_size(600, 600) self.add_events(gdk.BUTTON_PRESS_MASK | gdk.KEY_PRESS_MASK | gdk.KEY_RELEASE_MASK) def plot_row(self, treeview, path, view_column): ind, = path # get the index into data points = self.data[ind, :] self.line.set_ydata(points) self.canvas.draw() def add_columns(self): model = self.treeview.get_model() renderer = gtk.CellRendererText() for i in range(self.numCols): column = gtk.TreeViewColumn('%d' % i, gtk.CellRendererText(), text=i) self.treeview.append_column(column) def create_model(self): types = [gobject.TYPE_DOUBLE] * self.numCols store = gtk.ListStore(*types) for row in self.data: iter = store.append() pairs = [] for i, num in enumerate(row): pairs.extend((i, num)) store.set(iter, *pairs) return store
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))