Re: [Pyx-user] help regarding the plot From: Michael Schindler - 2004-01-21 18:52 ```Hello Sudheer, On 21.01.04, Sudheer Phani wrote: > If I use graph.line() option then all these 5 points are joined with > a line. > > If i were to draw the same graph something like in stem in Matlab... > how would i do it using PYX > > in stem function for each of 5 points to x-axis for e.g from > point(1,4) a line is drawn from (1,4) to (1,0) on x-axis like wise > for the rest of the points I fear that there is no ready-made solution to your problem yet. You can use the following workaround, which is only a small extension to the minimal example: ######## python code ########################### # read x, y values from your datafile d = data.datafile("minimal.dat") # extract the x and y values separately xvals = d.getcolumn(1) yvals = d.getcolumn(2) # plot the top line of your data with a line # (or with symbols, if you like) g = graph(width=8) g.plot(graph.data(d, x=1, y=2), style=graph.line()) # finish the graph so that all axes are fixed g.finish() # now comes the workaround: you can draw lines on the graph-canvas # directly. Use g.pos() for accessing the data-coordinate system: for x,y in zip(xvals,yvals): g.stroke(path.line(g.pos(x,y)[0], g.pos(x,y)[1], g.pos(x,0)[0], g.pos(x,0)[1])) g.writetofile("minimal") ################################################ I hope this answers your question, unfortunately I do not know what the "stem" function in Matlab is ... Best greetings, Michael. -- "A mathematician is a device for turning coffee into theorems" Paul Erdös. ```

 [Pyx-user] help regarding the plot From: Sudheer Phani - 2004-01-21 17:14 ```Hello I am looking for help regarding the plot. for example If I have y = [2,4,,6,8,10 ] and want to plot the values of x using some of those examples given in the webpages http://pyx.sourceforge.net/examples.html Then we would plot taking the index on the x-axis and y(array y) values on y-axis. using the following code g = graph.graphxy(width=8) g.plot(graph.data("minimal.dat", x=1, y=2)) g.writetofile("minimal") I would get the 5 points with X marks for the corresponding (x,y) points. # my (x,y) points are [(0,2),[1,4],[2,6],[3,8],[4,10]) If I use graph.line() option then all these 5 points are joined with a line. If i were to draw the same graph something like in stem in Matlab... how would i do it using PYX in stem function for each of 5 points to x-axis for e.g from point(1,4) a line is drawn from (1,4) to (1,0) on x-axis like wise for the rest of the points Thanks Sudheer ```
 Re: [Pyx-user] help regarding the plot From: Michael Schindler - 2004-01-21 18:52 ```Hello Sudheer, On 21.01.04, Sudheer Phani wrote: > If I use graph.line() option then all these 5 points are joined with > a line. > > If i were to draw the same graph something like in stem in Matlab... > how would i do it using PYX > > in stem function for each of 5 points to x-axis for e.g from > point(1,4) a line is drawn from (1,4) to (1,0) on x-axis like wise > for the rest of the points I fear that there is no ready-made solution to your problem yet. You can use the following workaround, which is only a small extension to the minimal example: ######## python code ########################### # read x, y values from your datafile d = data.datafile("minimal.dat") # extract the x and y values separately xvals = d.getcolumn(1) yvals = d.getcolumn(2) # plot the top line of your data with a line # (or with symbols, if you like) g = graph(width=8) g.plot(graph.data(d, x=1, y=2), style=graph.line()) # finish the graph so that all axes are fixed g.finish() # now comes the workaround: you can draw lines on the graph-canvas # directly. Use g.pos() for accessing the data-coordinate system: for x,y in zip(xvals,yvals): g.stroke(path.line(g.pos(x,y)[0], g.pos(x,y)[1], g.pos(x,0)[0], g.pos(x,0)[1])) g.writetofile("minimal") ################################################ I hope this answers your question, unfortunately I do not know what the "stem" function in Matlab is ... Best greetings, Michael. -- "A mathematician is a device for turning coffee into theorems" Paul Erdös. ```
 Re: [Pyx-user] help regarding the plot From: Andre Wobst - 2004-01-22 08:24 ```Hi, On 21.01.04, Michael Schindler wrote: > ######## python code ########################### > # read x, y values from your datafile > d = data.datafile("minimal.dat") > > # extract the x and y values separately > xvals = d.getcolumn(1) > yvals = d.getcolumn(2) > > # plot the top line of your data with a line > # (or with symbols, if you like) > g = graph(width=8) > g.plot(graph.data(d, x=1, y=2), style=graph.line()) > > # finish the graph so that all axes are fixed > g.finish() > > # now comes the workaround: you can draw lines on the graph-canvas > # directly. Use g.pos() for accessing the data-coordinate system: > for x,y in zip(xvals,yvals): > g.stroke(path.line(g.pos(x,y)[0], g.pos(x,y)[1], > g.pos(x,0)[0], g.pos(x,0)[1])) > > g.writetofile("minimal") > ################################################ Some additional notes: 1) You even may want to skip the g.plot(...) completely. Then the graph will not know about the axis ranges, so you have to provide axes with fixed ranges in the graph constructor. This would look like: g = graph.graphxy(width=8, x=graph.linaxis(min=0, max=10), y=graph.linaxis(min=0, max=10)) 2) When you want to plot data, you already have within python lists, you can construct a data instance yourself to use them in plot methods of the graph. An example would be: d = data.data([[1, 1], [2, 4], [3, 9], [4, 16], [5, 25]]) The valid column numbers are 0 and 1 for this case. Note that when reading a dataset from a file the columns are numbered from 1, while the column 0 is added automatically and contains the line number. 3) It is possible to create own data styles to be used in the graph. While this is not yet well documented, you have to look into the graph sources for that. I should note, that the graph styles are subject of a complete redesign and documentation in the forthcoming releases. André -- by _ _ _ Dr. André Wobst / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX (_/ \_)_/\_/ visit http://pyx.sourceforge.net/ ```
 Re: [Pyx-user] help regarding the plot From: Sudheer Phani - 2004-01-22 12:58 ```Hi Michael I some how could nt the graph i wanted to. Well abt the stem function in the matlab. eg y = x*x for x in the range (0,5) we have y = [0,1,4,9,16] when i stem(y) in matlab ... we get a graph some thing like this !!! ^ Y | | | | a | | | x | | | i | | | | s | | | | | | | | | | |---------------------------> 0 1 2 3 4 X-axis ----> where the height of each line corresponds to the value of y i.e. (0,1,4,9,16) for x = [0,1,2,3,4] regds Sudheer > Hello Sudheer, > > On 21.01.04, Sudheer Phani wrote: > > If I use graph.line() option then all these 5 points are joined with > > a line. > > > > If i were to draw the same graph something like in stem in Matlab... > > how would i do it using PYX > > > > in stem function for each of 5 points to x-axis for e.g from > > point(1,4) a line is drawn from (1,4) to (1,0) on x-axis like wise > > for the rest of the points > > I fear that there is no ready-made solution to your problem yet. You > can use the following workaround, which is only a small extension to > the minimal example: > > ######## python code ########################### > # read x, y values from your datafile > d = data.datafile("minimal.dat") > > # extract the x and y values separately > xvals = d.getcolumn(1) > yvals = d.getcolumn(2) > > # plot the top line of your data with a line > # (or with symbols, if you like) > g = graph(width=8) > g.plot(graph.data(d, x=1, y=2), style=graph.line()) > > # finish the graph so that all axes are fixed > g.finish() > > # now comes the workaround: you can draw lines on the graph-canvas > # directly. Use g.pos() for accessing the data-coordinate system: > for x,y in zip(xvals,yvals): > g.stroke(path.line(g.pos(x,y)[0], g.pos(x,y)[1], > g.pos(x,0)[0], g.pos(x,0)[1])) > > g.writetofile("minimal") > ################################################ > > I hope this answers your question, unfortunately I do not know what > the "stem" function in Matlab is ... > > Best greetings, > Michael. > > ```