Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## pyx-user

 [PyX-user] x position of bar From: Stathis Sideris - 2006-04-21 15:43:21 ```Hello everyone, I'm looking for a way to find the horizontal (x) position of a bar in a bar graph. I need it because I would like to draw some graphics aligned underneath each of the bars. The following code does find the position of the right edge of each of the bars, but it would be more useful to be able to find where the middle of each bar is. If I knew the width of each bar I could calculate the position of its middle by doing: x_middle = x_right - width/2, but I don't really know how to do that either. Thanks in advance, Stathis from pyx import * d = graph.data.list([ ("A", 1404), ("B", 918), ("C", 850) ], y=2, xname=1) g = graph.graphxy( width=8, x=graph.axis.bar(), y=graph.axis.linear(min=0, max=2000) ) g.plot(d, [ graph.style.bar([color.rgb.white]), graph.style.text("y")]) g.dolayout() x = g.axes["x"].convert(("A", 1)); x = x * g.width + g.xpos; g.stroke(path.line(x, g.ypos, x, g.ypos + g.height)); x = g.axes["x"].convert(("B", 1)); x = x * g.width + g.xpos; g.stroke(path.line(x, g.ypos, x, g.ypos + g.height)); x = g.axes["x"].convert(("C", 1)); x = x * g.width + g.xpos; g.stroke(path.line(x, g.ypos, x, g.ypos + g.height)); g.writePDFfile("graph") ```
 Re: [PyX-user] x position of bar From: Andre Wobst - 2006-04-24 05:28:46 ```Hi Stathis, On 21.04.06, Stathis Sideris wrote: > I'm looking for a way to find the horizontal (x) position of a bar in a > bar graph. > > x = g.axes["x"].convert(("A", 1)); A bar axis is an axis, which is constructed out of set of linear axes of range 0 to 1 -- for each discrete bar value one linear axis. So you can modify the 1 in the line above to 0 to get the left point of the bar and to 0.5 to get the middle of the bar. Beside that you may consider writing an own graph style for your use-case (depending on whether you want to use your specific style needs in several plots). Its quite easy to access the middle of the bar, as the (implicit) parpos style already prepares this point (for use by the text or the errorbar styles). You may start from the graph.style.text-class, which really are quite a few lines of code and modify it to your needs. HTH, André -- by _ _ _ Dr. André Wobst / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ ```