## [PyX-user] "empty sequence" when it is not (graphxyz)

 [PyX-user] "empty sequence" when it is not (graphxyz) From: Michael J Gruber - 2010-06-21 16:18:34 ```I'm getting somewhat frustrated with the graphxyz interface (or my understanding thereof). For good measure, I'm trying to plot a sphere. Now, no matter what I do, there seems to be some clipping/whatever going on which deletes points from my supplied list of points. The code below works for simple expressions like "p, sin(t), sin(t)" but not for the one below nor for the one commented out (sphere). I tried setting the axes ranges so that nothing should get clipped/removed. Why are nodes being deleted? (Tested with 0.10 as well as trunk.) Hoping for help... Michael from pyx import * from math import sin, cos, pi N = 10 g = graph.graphxyz(size=4, x=graph.axis.linear(min=-1,max=1), y=graph.axis.linear(min=-1,max=1),z=graph.axis.linear(min=-1,max=1)) ps = [ 2*pi*i/N for i in range(N+1) ] ts = [ pi*i/N for i in range(N+1) ] #xyz = [ [cos(t)*cos(p), cos(t)*sin(p), sin(t)] for t in ts for p in ps] xyz = [ [cos(p), sin(p), sin(t)] for t in ts for p in ps] g.plot(graph.data.points(xyz, x=1, y=2, z=3), [graph.style.surface(backcolor=None,gridcolor=color.gray.black)]) g.writePDFfile(__file__[:-3]) /usr/lib64/python2.6/site-packages/pyx/text.py:888: DeprecationWarning: os.popen4 is deprecated. Use the subprocess module. self.texinput, self.texoutput = os.popen4("%s%s %s" % (self.mode, ipcflag, self.texfilename), "t", 0) Traceback (most recent call last): File "kugel.py", line 15, in g.writePDFfile(__file__[:-3]) File "/usr/lib64/python2.6/site-packages/pyx/canvas.py", line 330, in wrappedindocument return method(d, file) File "/usr/lib64/python2.6/site-packages/pyx/document.py", line 161, in writePDFfile pdfwriter.PDFwriter(self, file, *args, **kwargs) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 475, in __init__ catalog = PDFcatalog(document, self, registry) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 155, in __init__ self.PDFpages = PDFpages(document, writer, registry) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 212, in __init__ page = PDFpage(page, pageno, self, writer, registry) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 238, in __init__ self.PDFcontent = PDFcontent(page, writer, self.pageregistry) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 267, in __init__ page.processPDF(contentfile, writer, acontext, registry, self.bbox) File "/usr/lib64/python2.6/site-packages/pyx/document.py", line 141, in processPDF self._process("processPDF", *args) File "/usr/lib64/python2.6/site-packages/pyx/document.py", line 81, in _process getattr(self.canvas, processMethod)(canvasfile, writer, context, registry, bbox) File "/usr/lib64/python2.6/site-packages/pyx/graph/graph.py", line 167, in processPDF canvas.canvas.processPDF(self, file, writer, context, registry, bbox) File "/usr/lib64/python2.6/site-packages/pyx/canvas.py", line 216, in processPDF item.processPDF(file, writer, context, registry, nbbox) File "/usr/lib64/python2.6/site-packages/pyx/mesh.py", line 127, in processPDF thisbbox = self.bbox() File "/usr/lib64/python2.6/site-packages/pyx/mesh.py", line 99, in bbox return bbox.bbox_pt(min([node.coords_pt[0] for element in self.elements for node in element.nodes]), ValueError: min() arg is an empty sequence ```

 [PyX-user] "empty sequence" when it is not (graphxyz) From: Michael J Gruber - 2010-06-21 16:18:34 ```I'm getting somewhat frustrated with the graphxyz interface (or my understanding thereof). For good measure, I'm trying to plot a sphere. Now, no matter what I do, there seems to be some clipping/whatever going on which deletes points from my supplied list of points. The code below works for simple expressions like "p, sin(t), sin(t)" but not for the one below nor for the one commented out (sphere). I tried setting the axes ranges so that nothing should get clipped/removed. Why are nodes being deleted? (Tested with 0.10 as well as trunk.) Hoping for help... Michael from pyx import * from math import sin, cos, pi N = 10 g = graph.graphxyz(size=4, x=graph.axis.linear(min=-1,max=1), y=graph.axis.linear(min=-1,max=1),z=graph.axis.linear(min=-1,max=1)) ps = [ 2*pi*i/N for i in range(N+1) ] ts = [ pi*i/N for i in range(N+1) ] #xyz = [ [cos(t)*cos(p), cos(t)*sin(p), sin(t)] for t in ts for p in ps] xyz = [ [cos(p), sin(p), sin(t)] for t in ts for p in ps] g.plot(graph.data.points(xyz, x=1, y=2, z=3), [graph.style.surface(backcolor=None,gridcolor=color.gray.black)]) g.writePDFfile(__file__[:-3]) /usr/lib64/python2.6/site-packages/pyx/text.py:888: DeprecationWarning: os.popen4 is deprecated. Use the subprocess module. self.texinput, self.texoutput = os.popen4("%s%s %s" % (self.mode, ipcflag, self.texfilename), "t", 0) Traceback (most recent call last): File "kugel.py", line 15, in g.writePDFfile(__file__[:-3]) File "/usr/lib64/python2.6/site-packages/pyx/canvas.py", line 330, in wrappedindocument return method(d, file) File "/usr/lib64/python2.6/site-packages/pyx/document.py", line 161, in writePDFfile pdfwriter.PDFwriter(self, file, *args, **kwargs) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 475, in __init__ catalog = PDFcatalog(document, self, registry) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 155, in __init__ self.PDFpages = PDFpages(document, writer, registry) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 212, in __init__ page = PDFpage(page, pageno, self, writer, registry) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 238, in __init__ self.PDFcontent = PDFcontent(page, writer, self.pageregistry) File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 267, in __init__ page.processPDF(contentfile, writer, acontext, registry, self.bbox) File "/usr/lib64/python2.6/site-packages/pyx/document.py", line 141, in processPDF self._process("processPDF", *args) File "/usr/lib64/python2.6/site-packages/pyx/document.py", line 81, in _process getattr(self.canvas, processMethod)(canvasfile, writer, context, registry, bbox) File "/usr/lib64/python2.6/site-packages/pyx/graph/graph.py", line 167, in processPDF canvas.canvas.processPDF(self, file, writer, context, registry, bbox) File "/usr/lib64/python2.6/site-packages/pyx/canvas.py", line 216, in processPDF item.processPDF(file, writer, context, registry, nbbox) File "/usr/lib64/python2.6/site-packages/pyx/mesh.py", line 127, in processPDF thisbbox = self.bbox() File "/usr/lib64/python2.6/site-packages/pyx/mesh.py", line 99, in bbox return bbox.bbox_pt(min([node.coords_pt[0] for element in self.elements for node in element.nodes]), ValueError: min() arg is an empty sequence ```
 Re: [PyX-user] "empty sequence" when it is not (graphxyz) From: André Wobst - 2010-06-21 21:09:43 Attachments: smime.p7s ```Michael, Sorry, surface is for rectangular grids only. Quoting the manual "Draws a surface of a rectangular grid. Each rectangle is divided into 4 triangles." You can use points and lines for any kind of data, but this might not at all help you. However, graphxyz might still be useful to you: You can use it for conversion of 3-dimensional points to two dimensions (with all the features like easily rotate the coordinate system, change projectors, etc.). Here's an example: from pyx import * from math import sin, cos, pi g = graph.graphxyz(size=4, x=graph.axis.linear(min=-1,max=1), y=graph.axis.linear(min=-1,max=1),z=graph.axis.linear(min=-1,max=1)) Ax, Ay = g.pos(-1,-1,-1) Bx, By = g.pos(-1,1,-1) Cx, Cy = g.pos(1,1,-1) Dx, Dy = g.pos(1,-1,-1) Ex, Ey = g.pos(-1,-1,1) Fx, Fy = g.pos(-1,1,1) Gx, Gy = g.pos(1,1,1) Hx, Hy = g.pos(1,-1,1) c = canvas.canvas() c.stroke(path.line(Ax, Ay, Bx, By)) c.stroke(path.line(Bx, By, Cx, Cy)) c.stroke(path.line(Cx, Cy, Dx, Dy)) c.stroke(path.line(Dx, Dy, Ax, Ay)) c.stroke(path.line(Ex, Ey, Fx, Fy)) c.stroke(path.line(Fx, Fy, Gx, Gy)) c.stroke(path.line(Gx, Gy, Hx, Hy)) c.stroke(path.line(Hx, Hy, Ex, Ey)) c.stroke(path.line(Ax, Ay, Ex, Ey)) c.stroke(path.line(Bx, By, Fx, Fy)) c.stroke(path.line(Cx, Cy, Gx, Gy)) c.stroke(path.line(Dx, Dy, Hx, Hy)) c.writePDFfile(__file__[:-3]) (I just found a bug in the pos methods, hence you need to fetch the current svn HEAD to use this functionality. However, I always planed to make this possible on the graphxyz -- just missed to properly test this functionality. Note that you need the graphxyz here, as the projectors themselfs are not able to define the coordinate system. You need axes for that. As shown in the example you may draw on a separate canvas. You may, however, also stroke the on the graph and write the graph to a file. Than the axis are shown (according to their painters setting).) Best, André Am 21.06.2010 um 18:17 schrieb Michael J Gruber: > I'm getting somewhat frustrated with the graphxyz interface (or my > understanding thereof). > > For good measure, I'm trying to plot a sphere. Now, no matter what I do, > there seems to be some clipping/whatever going on which deletes points > from my supplied list of points. > > The code below works for simple expressions like "p, sin(t), sin(t)" but > not for the one below nor for the one commented out (sphere). I tried > setting the axes ranges so that nothing should get clipped/removed. Why > are nodes being deleted? (Tested with 0.10 as well as trunk.) > > Hoping for help... > Michael > > > from pyx import * > from math import sin, cos, pi > > N = 10 > g = graph.graphxyz(size=4, x=graph.axis.linear(min=-1,max=1), > y=graph.axis.linear(min=-1,max=1),z=graph.axis.linear(min=-1,max=1)) > > ps = [ 2*pi*i/N for i in range(N+1) ] > ts = [ pi*i/N for i in range(N+1) ] > > #xyz = [ [cos(t)*cos(p), cos(t)*sin(p), sin(t)] for t in ts for p in ps] > xyz = [ [cos(p), sin(p), sin(t)] for t in ts for p in ps] > g.plot(graph.data.points(xyz, > x=1, y=2, z=3), > [graph.style.surface(backcolor=None,gridcolor=color.gray.black)]) > > g.writePDFfile(__file__[:-3]) > > > /usr/lib64/python2.6/site-packages/pyx/text.py:888: DeprecationWarning: > os.popen4 is deprecated. Use the subprocess module. > self.texinput, self.texoutput = os.popen4("%s%s %s" % (self.mode, > ipcflag, self.texfilename), "t", 0) > Traceback (most recent call last): > File "kugel.py", line 15, in > g.writePDFfile(__file__[:-3]) > File "/usr/lib64/python2.6/site-packages/pyx/canvas.py", line 330, in > wrappedindocument > return method(d, file) > File "/usr/lib64/python2.6/site-packages/pyx/document.py", line 161, > in writePDFfile > pdfwriter.PDFwriter(self, file, *args, **kwargs) > File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 475, > in __init__ > catalog = PDFcatalog(document, self, registry) > File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 155, > in __init__ > self.PDFpages = PDFpages(document, writer, registry) > File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 212, > in __init__ > page = PDFpage(page, pageno, self, writer, registry) > File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 238, > in __init__ > self.PDFcontent = PDFcontent(page, writer, self.pageregistry) > File "/usr/lib64/python2.6/site-packages/pyx/pdfwriter.py", line 267, > in __init__ > page.processPDF(contentfile, writer, acontext, registry, self.bbox) > File "/usr/lib64/python2.6/site-packages/pyx/document.py", line 141, > in processPDF > self._process("processPDF", *args) > File "/usr/lib64/python2.6/site-packages/pyx/document.py", line 81, in > _process > getattr(self.canvas, processMethod)(canvasfile, writer, context, > registry, bbox) > File "/usr/lib64/python2.6/site-packages/pyx/graph/graph.py", line > 167, in processPDF > canvas.canvas.processPDF(self, file, writer, context, registry, bbox) > File "/usr/lib64/python2.6/site-packages/pyx/canvas.py", line 216, in > processPDF > item.processPDF(file, writer, context, registry, nbbox) > File "/usr/lib64/python2.6/site-packages/pyx/mesh.py", line 127, in > processPDF > thisbbox = self.bbox() > File "/usr/lib64/python2.6/site-packages/pyx/mesh.py", line 99, in bbox > return bbox.bbox_pt(min([node.coords_pt[0] for element in > self.elements for node in element.nodes]), > ValueError: min() arg is an empty sequence > > > ------------------------------------------------------------------------------ > ThinkGeek and WIRED's GeekDad team up for the Ultimate > GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the > lucky parental unit. See the prize list and enter to win: > http://p.sf.net/sfu/thinkgeek-promo > _______________________________________________ > PyX-user mailing list > PyX-user@... > https://lists.sourceforge.net/lists/listinfo/pyx-user -- by _ _ _ Dr. André Wobst, Amselweg 22, 85716 Unterschleißheim / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ ```
 Re: [PyX-user] "empty sequence" when it is not (graphxyz) From: Michael J Gruber - 2010-06-22 07:10:03 ```Hi André, André Wobst venit, vidit, dixit 21.06.2010 22:31: > Michael, > > Sorry, surface is for rectangular grids only. Quoting the manual > "Draws a surface of a rectangular grid. Each rectangle is divided > into 4 triangles." I guess my problem is that I don't know what a rectangular grid is ;) Using graph.data.points etc. one can pass quite arbitrary point sets to graph.plot, i.e. point sets which are not necessarily "graphs", and with no special distinction for the first few coordinates/columns. graph.function and graph.functionxy generate very special 2D point sets: y is a function of x (the set is a graph), and the x values are ordered and equally spaced. But there is no such thing for generating 3D point sets. I even remember that a suggestion for 3D analogs (graph of a function of 2 variables) was dismissed because the interface was supposed to be more general. graph.style.surface seems to assume at least some ordering of the points, such as left-to-right then back-to-front, and, maybe, rectangularity in the strict sense. In that case there should be a 3D data provider which takes 2 (ordered) lists (x values, y values) and a function argument and generates a data instance suitable for style.surface, or a helper which generates the x-y-grid. I guess in numpy that would be something like "zip(outer(x, ones(...)), outer(ones(...), y)" or similar. > > You can use points and lines for any kind of data, but this might not > at all help you. However, graphxyz might still be useful to you: You > can use it for conversion of 3-dimensional points to two dimensions > (with all the features like easily rotate the coordinate system, > change projectors, etc.). Here's an example: Oh, I do consider graphxyz useful for graphs of functions of 2 variables. And your example shows another use case. Also, being able to plot (style.line) a parametric function of 1 variable on top of a 3D graph is cool, for example plotting selected level lines on top of a surface. [There's no hidden line removal, of course.] It's just that I started experimenting with graphxyz again, thinking about the best ways to do e.g. the following with the current interface, or with numpy/pyx or a future interface: 1) plot f(x,y) on a rectangular domain 2) plot f(x,y) on a non-rectangular domain (say, defined by a z-range for f 3) parametric plot: [x(t,s),y(t,s),z(t,s)] I can do 1) of course, but the interface could be simpler. Using non-uniformly spaced points (still rectangular) works and is useful. I can do 2) of course, but it suffers from "ragged boundaries" because I can only deletes points, not nodes or triangles. [That was my starting point for experimenting with non-rectangular grids: Adding some points at the boundary.] 3) Has been answered completely I'm afraid :| Michael ```