示例#1
0
文件: nested.py 项目: strawlab/benu
import tempfile
import random
import matplotlib.pyplot as plt

from benu.benu import Canvas

OUTER = 500

#---------

cm = plt.get_cmap('jet')
outer = OUTER

tmp_fname = tempfile.mktemp('.png')
canv = Canvas(tmp_fname, OUTER, OUTER)

while outer > 10:
    device_rect = (0,0,outer,outer)
    user_rect   = (0,0,outer,outer)
    with canv.set_user_coords(device_rect, user_rect):
        canv.poly([0,0,outer,outer,0],
                  [0,outer,outer,0,0],
                  color_rgba=cm(random.randrange(0,cm.N))
    )
    outer = outer // 2

canv.save()
print tmp_fname

示例#2
0
文件: demo.py 项目: strawlab/benu
        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()

# this test is broken...
## with c.set_user_coords(1,2):
##     pass

print tmp_fname
示例#3
0
文件: image.py 项目: strawlab/benu
    device_y1 = TARGET_OUT_H-MARGIN
)
panels["plot"] = dict(
    width = 500,
    height = 400,
    device_x0 = 0.5*TARGET_OUT_W + MARGIN//2,
    device_x1 = 1.0*TARGET_OUT_W - MARGIN//2,
    device_y0 = MARGIN,
    device_y1 = TARGET_OUT_H-MARGIN
)
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),