%run NBCONFIG.ipynb from pyparty import Canvas, splot, showim c=Canvas.random_circles(n=15, background='honeydew', pcolor='random') c.show(grid=True) c.grid ax1, ax2, ax3, ax4 = splot(2,2, figsize=(10,10)) c.show(ax1, gcolor='blue', title='standard') c.show(ax2, gcolor='blue', gunder=True, title='grid under') c.patchshow(ax3, gcolor='orange', gunder=True, title='patches grid under') c.patchshow(ax4, gcolor='orange', gstyle='--', title='patches gstyle = --'); from pyparty import splot ax1, ax2 = splot(1,2, figsize=(10,10)) c.grid.xdiv=5 c.show(ax1, gcolor='black', title='5 "X" divisions') c.reset_grid() c.grid.yspacing=20 c.patchshow(ax2, gcolor=(1,0,0), title='20 pixels per "Y" division') c.reset_grid(); axs = splot(2,2) c.show(axs[0], grid='centers', title='centers') c.show(axs[1], grid='corners', title='corners') c.show(axs[2], grid='hlines', title='hlines') c.show(axs[3], grid='vlines', title='vlines') # Zoom in to for clarity for ax in axs: ax.set_xlim(-2,37) ax.set_ylim(37,-2) #Make a blank 512x512 array (ones=white) blank = np.ones((512,512,3)) #Get the indicies of corners, centers blank[c.grid.centers] = (1,0,0) #r blank[c.grid.hlines] = (0,1,0) #g blank[c.grid.corners] = (0,0,1) #b imshow(blank) plt.xlim(-1,104) plt.ylim(104,-1); from skimage.data import moon, lena cnew=Canvas(background=moon()) cnew.grid.xdiv=10 cnew.grid.ydiv=20 for (cx, cy) in cnew.gpairs('centers'): cnew.add('circle', radius=10, center=(cx,cy), color='orange') for idx, (cx, cy) in enumerate( cnew.gpairs('corners') ): cnew.add('ellipse', xradius=10, yradius=30, center=(cx,cy), color='white', phi=45*idx) cnew.patchshow(gcolor='yellow', gstyle='--'); from pyparty.tools.grids import Grid, TiledGrid from pyparty import showim ax1, ax2 = splot(1,2) g = Grid() tg = TiledGrid(xpoints=20, ypoints=20) showim(g.zz, ax1) showim(tg.zz, ax2) print g print tg x=np.linspace(0,1,512) y=np.linspace(0,1,512) XX, YY = np.meshgrid(x,y) ax1, ax2 = splot(1,2) showim(XX, ax1, 'jet') showim(YY, ax2, 'jet'); def justXX(xx, yy): return xx def add_em(xx, yy): return xx+yy ax1, ax2 = splot(1,2) showim(justXX(XX,YY), ax1) showim(add_em(XX,YY), ax2); ax1, ax2 = splot(1,2) tg1 = TiledGrid(style='d') tg2 = TiledGrid(style='d', reverse=True) showim(tg1.zz, ax1, 'jet') showim(tg2.zz, ax2, 'jet'); ax1, ax2 = splot(1,2) def ztrigfcn(xx, yy, power=2): return abs(np.cos(xx**power) + np.sin(yy**power)) tg.set_zfcn(ztrigfcn) g.set_zfcn(ztrigfcn) showim(g.zz, ax1, 'Blues') showim(tg.zz,ax2, 'Blues'); def zint(xx, yy): return xx.astype(int) + yy.astype(int) g_foo = Grid() g_foo.set_zfcn(zint) showim(g_foo.zz, 'YlGn', title="Tiling through zfunction"); ax1, ax2 = splot(1,2) c.background = g c.show(ax1, 'Blues_r') c.reset_background() c.background = tg1 c.show(ax2, 'jet', bgonly=True); from skimage.data import lena ax1, ax2 = splot(1,2) g=Grid(style='h') shadow_lena = g.blend_bg( lena(), weight=0.75 ) g.set_zfcn(ztrigfcn, power=2.25) trippy_lena = g.blend_bg( lena(), weight=.25 ) showim(shadow_lena, ax1, 'gray', title='horiz. shadow') showim(trippy_lena, ax2, 'YlOrRd_r', title='trig pattern'); tiles = c.grid.tiles c = Canvas( background=moon() ) img = c.image eventiles = tiles[::2] # Paint every other tile blue for tile in eventiles: img[tile] = (0,0,1) showim(img); tflat = c.grid.as_tiles(key='flat') # or key=True t2d = c.grid.as_tiles(key='2d') for i in range(5): print tflat.keys()[i], t2d.keys()[i] tile5 = tflat[5] tile16 = t2d[(9,9)] #index starts at 0 img[tile5] = (1,0,0) #red img[tile16] = (1,1,0) #yellow showim(img); c.background = img oddtiles = tflat.keys()[1::2] for idx, (cx, cy) in enumerate(c.gpairs('centers')): if idx in oddtiles: c.add('circle', radius=10, center=(cx,cy)) c.show(); img = c.image for d in c.grid.dlines: img[d] = (1,0,0) #red for nd in c.grid.dlines_neg: img[nd] = (0,1,0) #green showim(img);