Etrade Griffiths venit, vidit, dixit 2006-06-09 12:58:
> Hi
> 
> sorry if this is seems a trivial request but I am trying to read a set of 
> polygons from file and plot them using PyX.  PyX runs OK (ie no errors) but 
> nothing appears on the canvas!  The file contains data in this form
> 
> poly_1, x0, y0
> poly_1, x1, y1
> ...
> poly_2, x0, y0
> 
> Here is a code snippet
...

Make sure you check the parts you didn't show us: the parsing of the
input (comparing poly identifiers) and the handling of the very first
and very last points. I'll attach some (ugly) code that works here,
using the same structure you're trying to use.

Note that it may be more efficient to construct one path only (add a
moveto again after a closepath etc.) and stroke that single path in the
end; but it works either way.

Michael
from pyx import *

polys = [ ["poly1",0,0], ["poly1",0,2], ["poly1",1,1], ["poly1",2,2], 
["poly1",2,0],
          ["poly2",3,1], ["poly2",4,0], ["poly2",5,1], ["poly2",4,2] ]

c = canvas.canvas()
curpoly = "none"
p = None

for poly in polys:
  if poly[0] == curpoly:
    p.append(path.lineto(poly[1], poly[2]))
  else:
   if p:
     p.append(path.closepath())
     c.stroke(p)
   p = path.path(path.moveto(poly[1], poly[2]))
   curpoly = poly[0]

p.append(path.closepath())
c.stroke(p)

c.writeEPSfile(__file__[:-3])
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to