## [PyX-user] logarithmic axis and histogram

 [PyX-user] logarithmic axis and histogram From: Patrick Pletscher - 2006-02-17 09:41:21 ```Hi all, I want to illustrate some results by a histogram. However my data is very asymmetric, in the sense that some histogram-"peaks" are very big, while others are rather small. The usual way I illustrate such data is with a logarithmic y-axis, however with a histogram (instead of a normal plot), I'm not getting any further... Here a small test program: from pyx import * histo = [[1, 2353], [2, 80], [3, 18], [4, 14], [5, 12], [6, 12]] g = graph.graphxy(width=8, x=graph.axis.linear(min=0, max=12, title="rank")) g.plot(graph.data.list(histo, x=1, y=2), [graph.style.histogram(autohistogramaxisindex=0, steps=0)]) g.writePDFfile("minimal") This works, however if I add a y=graph.axis.log(min=1, max=8000, title="number") to the initialization of the g, I'm getting a math range error (pyx somehow wants to compute a log of 0). By inspecting the code of pyx/graph/axis/axis.py on line 81 and changing the code to something like: if float(value) < 0.01: return 0 else: return (math.log(float(value)) - math.log(data.min)) / (math.log(data.max) - math.log(data.min)) I at least get no error, and the plot looks as well not too bad. I however can not see, why we are computing a log of 0 here. Can somebody give my some hints how to solve this problem elegantly? One thing about the resulting histogram I find not too beautiful: neighbouring bins with same height get merged (no separating line between the two bins), can we prevent this? I would as well welcome suggestions about other approaches how to illustrate such data, e.g. splitgraphs (which suffered as well from log of 0). Thanks in advance for your help, I would really appreciate this. Could you please CC me, as I'm not subscribed to the list. Best regards, Patrick ```

 [PyX-user] logarithmic axis and histogram From: Patrick Pletscher - 2006-02-17 09:41:21 ```Hi all, I want to illustrate some results by a histogram. However my data is very asymmetric, in the sense that some histogram-"peaks" are very big, while others are rather small. The usual way I illustrate such data is with a logarithmic y-axis, however with a histogram (instead of a normal plot), I'm not getting any further... Here a small test program: from pyx import * histo = [[1, 2353], [2, 80], [3, 18], [4, 14], [5, 12], [6, 12]] g = graph.graphxy(width=8, x=graph.axis.linear(min=0, max=12, title="rank")) g.plot(graph.data.list(histo, x=1, y=2), [graph.style.histogram(autohistogramaxisindex=0, steps=0)]) g.writePDFfile("minimal") This works, however if I add a y=graph.axis.log(min=1, max=8000, title="number") to the initialization of the g, I'm getting a math range error (pyx somehow wants to compute a log of 0). By inspecting the code of pyx/graph/axis/axis.py on line 81 and changing the code to something like: if float(value) < 0.01: return 0 else: return (math.log(float(value)) - math.log(data.min)) / (math.log(data.max) - math.log(data.min)) I at least get no error, and the plot looks as well not too bad. I however can not see, why we are computing a log of 0 here. Can somebody give my some hints how to solve this problem elegantly? One thing about the resulting histogram I find not too beautiful: neighbouring bins with same height get merged (no separating line between the two bins), can we prevent this? I would as well welcome suggestions about other approaches how to illustrate such data, e.g. splitgraphs (which suffered as well from log of 0). Thanks in advance for your help, I would really appreciate this. Could you please CC me, as I'm not subscribed to the list. Best regards, Patrick ```
 Re: [PyX-user] logarithmic axis and histogram From: Joerg Lehmann - 2006-02-17 10:28:46 ```Hi Patrick, On 17.02.06, Patrick Pletscher wrote: [ snip ] > Here a small test program: > > > from pyx import * > histo = [[1, 2353], [2, 80], [3, 18], [4, 14], [5, 12], [6, 12]] > > g = graph.graphxy(width=8, > x=graph.axis.linear(min=0, max=12, title="rank")) > g.plot(graph.data.list(histo, x=1, y=2), > [graph.style.histogram(autohistogramaxisindex=0, steps=0)]) > g.writePDFfile("minimal") > > This works, however if I add a > y=graph.axis.log(min=1, max=8000, title="number") You have to add fromvalue=1 (or whatever fits) to arguments of the histogram style: graph.style.histogram(autohistogramaxisindex=0, steps=0, fromvalue=1) Best, Jörg ```
 Re: [PyX-user] logarithmic axis and histogram From: Patrick Pletscher - 2006-02-17 10:48:07 ```Hi Jörg, > > You have to add fromvalue=1 (or whatever fits) to arguments of the > histogram style: > > graph.style.histogram(autohistogramaxisindex=0, steps=0, fromvalue=1) > Wow, cool! That works nicely. Sorry for asking something documented, but I wasn't aware that this is what I was looking for. However by rereading the relevant section in the manual I found as well the option fillable=1, which did solve the second question (prevent merging of bins). Cool... Thanks again and best regards, Patrick ```
 Re: [PyX-user] logarithmic axis and histogram From: Andre Wobst - 2006-02-17 13:39:44 ```On 17.02.06, Patrick Pletscher wrote: > > You have to add fromvalue=1 (or whatever fits) to arguments of the > > histogram style: > > > > graph.style.histogram(autohistogramaxisindex=0, steps=0, fromvalue=1) > > > > Wow, cool! That works nicely. Sorry for asking something documented, but > I wasn't aware that this is what I was looking for. However by rereading > the relevant section in the manual I found as well the option > fillable=1, which did solve the second question (prevent merging of > bins). Cool... Hey, I wasn't aware of this "fillable=1 feature" as a workaround. (The fillable feature is originally designed for something else, namely to properly handle the case, when a histogram is cut by the graph boundaries. While you don't want to stroke along the graph boundaries, you need those path parts for filling. See the functional test http://cvs.sourceforge.net/viewcvs.py/pyx/pyx/test/functional/test_histogram.py?view=markup for some examples.) Beside that I think the merging of the bins clearly is a bug. I've found it myself recently when I played around with the histogramdata data provider. It's already on my todo list: http://cvs.sourceforge.net/viewcvs.py/pyx/pyx/CHANGES?r1=1.424&r2=1.425 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/ ```