Ejemplo n.º 1
0
# test the with statement using as
with canv.set_user_coords(device_rect, user_rect,
                          transform=transform) as canv2:
    for pt in pts:
        canv2.scatter( [pt[0]], [pt[1]] )

    # draw red boundary in user coords
    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 )
Ejemplo n.º 2
0
    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 )


#plot
p = panels["plot"]
device_rect,user_rect = get_panel_rects(p)
with canv.set_user_coords(device_rect, user_rect):
    with canv.get_figure(user_rect) as fig:
        ax = fig.add_subplot(111)
        ax.plot( [5,7,10], [5,7,10], 'r-' )
        set_foregroundcolor(ax, 'white')
        set_backgroundcolor(ax, 'black')
        fig.patch.set_facecolor('none')

#inset lena on bottom right hand corner of plot
p = panels["plot"]