canv2.plot( [ux0,ux0,ux1,ux1,ux0],[uy0,uy1,uy1,uy0,uy0], color_rgba=(1,0,0,1)) # test the with statement (not using as) with canv.set_user_coords(device_rect, user_rect, transform=transform): for pt in pts: canv.scatter( [pt[0]], [pt[1]], radius=0.5, color_rgba=(0.2,0.2,0.6,0.5) ) if 1: # draw boundary of above coord system canv.plot( [device_rect[0],device_rect[0], device_rect[0]+device_rect[2], device_rect[0]+device_rect[2], device_rect[0],], [device_rect[1],device_rect[1]+device_rect[3], device_rect[1]+device_rect[3],device_rect[1], device_rect[1],], color_rgba=(0,0.5,0,1) ) # dark green # draw blue star canv.poly( [0,50,100,0,100,0], [100,0,100,50,50,100], color_rgba=(0,0,1,1), edgewidth=5 ) for pt in pts: x,y = canv.get_transformed_point(pt[0],pt[1],device_rect,user_rect, transform=transform) canv.text( '%s, %s'%(pt[0],pt[1]), x,y ) canv.save()
actual_out_w, actual_out_h = negotiate_panel_size(panels) tmp_fname = tempfile.mktemp('.png') canv = Canvas(tmp_fname,actual_out_w,actual_out_h) canv.poly([0,0,actual_out_w,actual_out_w,0],[0,actual_out_h,actual_out_h,0,0], color_rgba=(0,0,0,1)) #big lena p = panels["lena"] device_rect,user_rect = get_panel_rects(p) with canv.set_user_coords(device_rect, user_rect): canv.imshow(lena, 0,0, filter='best' ) #in pixel coordinates! xpx = np.arange(50,150) ypx = (np.sin(xpx)*100) + 150 canv.plot(xpx,ypx, color_rgba=(1,0,0,1)) #draw 1/4 size lena in bottom left device_rect = ( 0, actual_out_h-(ih//4), iw//4, ih//4 ) user_rect = (0,0,ilena.shape[1], ilena.shape[0]) with canv.set_user_coords(device_rect, user_rect): canv.imshow(ilena, 0,0, filter='best' ) #in pixel coordinates col = 20; row = 80 canv.scatter([col], [row], color_rgba=(0.4,0,0.6,0.8), radius=6, markeredgewidth=5 )