From: Andre W. <wo...@us...> - 2004-01-22 08:24:20
|
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 / \ \ / ) wo...@us..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX (_/ \_)_/\_/ visit http://pyx.sourceforge.net/ |