## Re: [Pyx-user] Question on path.line and tick marks/labels

 Re: [Pyx-user] Question on path.line and tick marks/labels From: Andre Wobst - 2004-05-06 06:02:38 ```Hi, On 05.05.04, Owzar, Kouros wrote: > I was introduced to PyX a few days ago and I am trying > to produce a figure for a grant application. > > I have attempted to use path.line to add lines to a graphxy > object. The problem I am having is that the coordinates > that I have specified do not line up with the tick marks > of the axes of the graphxy object. > > To illustrate the problem, I have attached a toy example, > rather than the more complicated figure I am attempting to produce, > below. Thanks for providing a small example. > In this example, I want to add a (vertical) line segment, > which connects the points (0,2) to (2,2). So what I tried > is to use. > > g.stroke(path.line(2, 0, 2, 2)) > > That however seems to be connecting to other points (seemingly > it is connecting (1.6,0) to (1.6,1.6)). Right. The reason is, that already the path object is responsible for its positioning. So it is completely unknown, that you want to use the coordinate system defined by the graph axes for positioning of the points. Forunately you can ask a graph for the conversion (*). In order to do so, you have to first finish the graph (this is obviously important when you do not fix the axis ranges, but PyX always needs this step). So instead of your code g.stroke(path.line(2, 0, 2, 2)) you have to do: g.finish() x1, y1 = g.pos(2, 0) x2, y2 = g.pos(2, 2) g.stroke(path.line(x1, y1, x2, y2)) Note that when finishing the graph, it is also already inserted into its own canvas. Thus the line will be inserted on top of the graph (this can be noticed, when stroking with different colors etc.). You can change this behavior by not finishing the graph, but call the graphs dolayout-method instead. This would just fix the layout making g.pos-calls possible, but postpone the actuall drawing of the graph components. > Another question that I have is how to omit the display of > the tick marks and/or labels. There are different possibilities. The most easiest one to your question is to disable the default axis partitioner (which automatically creates a list of tick/label positions). In your example this would look like: g = graph.graphxy(width=6,height=6, x=graph.axis.linear(min=0,max=5,title=r"\$X\$", parter=None), y=graph.axis.linear(min=0,max=5,title=r"\$Y\$")) to disable all ticks/labels for the x-axis. You could also set your own partitioner, which inserts ticks, but no labels. An example of a None-automatic axis partitioner would be: parter=graph.axis.parter.lin([1, 0.5], []). as axis keyword argument. Note, that the second argument disables labels since they would be added at tick positions automatically when not specifying label positions at all. Another possibility would be to disable the painting of ticks and/or labels in the axis painter, while keeping them in the partition ... André (*) You could even be more verbose: ask the axis for a converion to graph coordinates and then the graph to convert that to an actual position on a canvas. The graph can also give you a geodesic between to points given in graph coordinates, which would be, in case of a graphxy, a straigt line as well ... -- by _ _ _ Dr. André Wobst / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX (_/ \_)_/\_/ visit http://pyx.sourceforge.net/ ```

 [Pyx-user] Question on path.line and tick marks/labels From: Owzar, Kouros - 2004-05-05 20:18:02 ```Hi. I was introduced to PyX a few days ago and I am trying to produce a figure for a grant application. I have attempted to use path.line to add lines to a graphxy object. The problem I am having is that the coordinates that I have specified do not line up with the tick marks of the axes of the graphxy object. To illustrate the problem, I have attached a toy example, rather than the more complicated figure I am attempting to produce, below. In this example, I want to add a (vertical) line segment, which connects the points (0,2) to (2,2). So what I tried is to use. g.stroke(path.line(2, 0, 2, 2)) That however seems to be connecting to other points (seemingly it is connecting (1.6,0) to (1.6,1.6)). Another question that I have is how to omit the display of the tick marks and/or labels. I would be very appreciative for any comments/suggestions. To the PyX developers: Many thanks and congratulations for a job well done. Sincerely, Kouros from pyx import * text.set(fontmaps="psfonts.cmz psfonts.amz") g = graph.graphxy(width=6,height=6, x=graph.axis.linear(min=0,max=5,title=r"\$X\$"), y=graph.axis.linear(min=0,max=5,title=r"\$Y\$")) g.plot(graph.data.function("x=y")) g.plot(graph.data.function("x=(y-2.5)**2")) #g.plot(graph.data.file("test.dat", x=1, y=2)) # test.dat # 1 1 # 2 2 # 3 3 g.stroke(path.line(2, 0, 2, 2), [style.linestyle.dashed]) g.writeEPSfile("test") Kouros Owzar Department of Biostatistics and Bioinformatics Duke University Medical Center Durham, NC 27710 E-mail: kouros.owzar@... Phone: (919)-681-1829 (CALGB) (919)-668-8505 (ACOSOG) Fax : (919)-681-8028 (CALGB) (919)-668-7122 (ACOSOG) ```
 Re: [Pyx-user] Question on path.line and tick marks/labels From: Andre Wobst - 2004-05-06 06:02:38 ```Hi, On 05.05.04, Owzar, Kouros wrote: > I was introduced to PyX a few days ago and I am trying > to produce a figure for a grant application. > > I have attempted to use path.line to add lines to a graphxy > object. The problem I am having is that the coordinates > that I have specified do not line up with the tick marks > of the axes of the graphxy object. > > To illustrate the problem, I have attached a toy example, > rather than the more complicated figure I am attempting to produce, > below. Thanks for providing a small example. > In this example, I want to add a (vertical) line segment, > which connects the points (0,2) to (2,2). So what I tried > is to use. > > g.stroke(path.line(2, 0, 2, 2)) > > That however seems to be connecting to other points (seemingly > it is connecting (1.6,0) to (1.6,1.6)). Right. The reason is, that already the path object is responsible for its positioning. So it is completely unknown, that you want to use the coordinate system defined by the graph axes for positioning of the points. Forunately you can ask a graph for the conversion (*). In order to do so, you have to first finish the graph (this is obviously important when you do not fix the axis ranges, but PyX always needs this step). So instead of your code g.stroke(path.line(2, 0, 2, 2)) you have to do: g.finish() x1, y1 = g.pos(2, 0) x2, y2 = g.pos(2, 2) g.stroke(path.line(x1, y1, x2, y2)) Note that when finishing the graph, it is also already inserted into its own canvas. Thus the line will be inserted on top of the graph (this can be noticed, when stroking with different colors etc.). You can change this behavior by not finishing the graph, but call the graphs dolayout-method instead. This would just fix the layout making g.pos-calls possible, but postpone the actuall drawing of the graph components. > Another question that I have is how to omit the display of > the tick marks and/or labels. There are different possibilities. The most easiest one to your question is to disable the default axis partitioner (which automatically creates a list of tick/label positions). In your example this would look like: g = graph.graphxy(width=6,height=6, x=graph.axis.linear(min=0,max=5,title=r"\$X\$", parter=None), y=graph.axis.linear(min=0,max=5,title=r"\$Y\$")) to disable all ticks/labels for the x-axis. You could also set your own partitioner, which inserts ticks, but no labels. An example of a None-automatic axis partitioner would be: parter=graph.axis.parter.lin([1, 0.5], []). as axis keyword argument. Note, that the second argument disables labels since they would be added at tick positions automatically when not specifying label positions at all. Another possibility would be to disable the painting of ticks and/or labels in the axis painter, while keeping them in the partition ... André (*) You could even be more verbose: ask the axis for a converion to graph coordinates and then the graph to convert that to an actual position on a canvas. The graph can also give you a geodesic between to points given in graph coordinates, which would be, in case of a graphxy, a straigt line as well ... -- by _ _ _ Dr. André Wobst / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX (_/ \_)_/\_/ visit http://pyx.sourceforge.net/ ```