From: <bfblockaim@ya...>  20050602 08:51:18

Thanks! That certainly works. Your reply indicates there is an easier way to do this. I would be grateful if you could show me. I would also like to be able to plot other primitives, such as colored triangles and polygons, beneath the map. Brian  Andre Wobst <wobsta@...> wrote: > Hi, > > On 28.05.05, bfblockaim@... wrote: > > Hello, > > > > Can anybody help me with turning on clipping > > when stroking world coast outlines in a graph? > > > > I attach the script + data, but if it does not get thru, > > here is a summary: > > > > g = graph.graphxy(height=8, width=16, > > x=graph.axis.linear(min=lonmin, max=lonmax, title=r'$\lambda$'), > > y=graph.axis.linear(min=latmin, max=latmax, title=r'$\phi$')) > > > > for a in lines: > > p = path.path(path.moveto(a[0],a[1])) > > for i in range(2,len(a),2): > > p.append(path.lineto(a[i],a[i+1])) > > p=p.transformed(tt) > > g.stroke(p) > > The point is, that graph canvases do not clip. We do not even (any > more) clip the regular graph content, since this could clip parts of > symbols and parts of the line when they "touch" the border. But this > is out of scope for you. > > You could use a linelike graph style for plotting your map (actually, > this would be a really nice feature) and use the clip calculation of > the existing grpah line style. But this is not what you asked for. Its > actually much easier. You can create a canvas which clips its content > to a given path. Your example would become: > > #!/usr/bin/env python > from pyx import * > import cPickle > # Plot a map and plot data points > > inp=open('world_coast.pickle','r') > stuff=cPickle.load(inp) > lines=stuff['lines'] > heads=stuff['heads'] > inp.close() > > lonmin=180. > lonmax=180. > latmin=90. > latmax=90. > #uncomment the following two line to show the problem > lonmax=0. > latmax=0. > g = graph.graphxy(height=8, width=16, > x=graph.axis.linear(min=lonmin, max=lonmax, title=r'$\lambda$'), > y=graph.axis.linear(min=latmin, max=latmax, title=r'$\phi$')) > #clipping happens on these three points: > a=[[50,60],[40,60],[30,50]] > g.plot(graph.data.list(a, x=1, y=2), > [graph.style.symbol(graph.style.symbol.circle, size=0.5, > symbolattrs=[deco.filled([color.rgb.green]), > deco.stroked([color.rgb.red])])]) > xmin,ymin=g.pos(lonmin,latmin) > xmax,ymax=g.pos(lonmax,latmax) > sx=(xmaxxmin)/(lonmaxlonmin) > sy=(ymaxymin)/(latmaxlatmin) > #tt=trafo.translate(lonmin,latmin) #note "translate", not "translated" > #tt=tt.scaled(sx) #note "scaled", not "scale" > #plot the map, notice problem with clipping > c = canvas.canvas([canvas.clip(path.rect(g.xpos, g.ypos, g.width, g.height)), > trafo.scale(sx), > trafo.translate(lonmin,latmin)]) > g.insert(c) > for a in lines: > p = path.path(path.moveto(a[0],a[1])) > for i in range(2,len(a),2): > p.append(path.lineto(a[i],a[i+1])) > #p=p.transformed(tt) > c.stroke(p) > g.writeEPSfile('plot_map') > > Note, that I also applied the transformation to the canvas, such that > you can stroke the untransformed lines to the canvas. Note, finally, > that a graph is nothing more like an ordinary canvas and we insert > your clipping canvas into that graph canvas. > > I hope I could give you some hints/advices ... > > > André > >  > by _ _ _ Dr. André Wobst > / \ \ / ) wobsta@..., http://www.wobsta.de/ > / _ \ \/\/ / PyX  High quality PostScript figures with Python & TeX > (_/ \_)_/\_/ visit http://pyx.sourceforge.net/ > > >  > This SF.Net email is sponsored by Yahoo. > Introducing Yahoo! Search Developer Network  Create apps using Yahoo! > Search APIs Find out how you can build Yahoo! directly into your own > Applications  visit http://developer.yahoo.net/?fr=offadysdnostgq22005 > _______________________________________________ > PyXuser mailing list > PyXuser@... > https://lists.sourceforge.net/lists/listinfo/pyxuser > 