import tempfile from benu.benu import Canvas from benu.utils import set_foregroundcolor, set_backgroundcolor import tempfile tmp_fname = tempfile.mktemp('.png') canv = Canvas(tmp_fname,500,500) device_rect = (100,100,300,300) ux0 = 0 uy0 = 0 uw = 50 uh = 50 ux1 = ux0+uw uy1 = uy0+uh user_rect = (ux0,uy0,uw,uh) #transform = 'rot 10' transform = 'rot -45' #transform = 'orig' pts = [ (0,0), (5,5), (30,30), (45,45), (1,3), (6,2), ] # test the with statement using as with canv.set_user_coords(device_rect, user_rect, transform=transform) as canv2:
device_y0 = MARGIN, 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,
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
import tempfile from benu.benu import Canvas from benu.utils import set_foregroundcolor, set_backgroundcolor tmp_fname = tempfile.mktemp('.png') canv = Canvas(tmp_fname,500,500) with canv.get_figure(500,500) as fig: ax = fig.add_subplot(111) ax.plot( [5,7,10], [5,7,10], 'r-' ) ax.set_xlabel('Xlabel') ax.set_ylabel('Ylabel') fig.patch.set_facecolor('none') canv.save() print tmp_fname