Hi again, FYI, I've solved my two remaining problems. The weird path/fill issue was worked around by clipping my data to the axis extents (which I specify already) before handing it to PyX to generate the path. And then I discovered that the entries in the key can be hidden by explicitly passing title=None when constructing my data.file object.
That normpath bug is still there, of course, unless it was already fixed in a more recent version. :) On a sidenote, I wonder if making a new style - some kind of combination of a line and an errorbar - would be a more robust approach. Certainly there are cases where displaying errorbars is not a good solution, such as when given a time series with hundreds of data points (as in my case), and an "errorregion" style would be quite handy. Sadly I don't have time to look into coding that. Peace, Brendon On October 2, 2013 13:04:56 Brendon Higgins wrote: > Hi Joerg, Andre, and all, > > Sorry that this is a bit long, but it covers several issues, so please bear > with me... > > I've been trying to implement this confidence band code that Joerg posted > last month, and it hasn't been smooth sailing. To start, some of the rows > of my data file have NA entries (literally "*" in the file, which I thought > was the recommended way), so my first problem was with on-the-fly > confidence-region calculations that, I've come to realize, have to manually > check for str values, otherwise Python will complain about mixed types > (e.g. that something like "$3 + 1" tries to concatenate an int to a str). I > don't see how to sensibly avoid that, so I guess that just has to be up to > the user to implement. > > The second issue I found is, I'm pretty sure, a bug in path.py. When trying > to reverse the path, I get an exception with trace ending like so: > File "/usr/lib/python2.7/dist-packages/pyx/path.py", line 1118, in > reversed return self.normpath().reversed() > File "/usr/lib/python2.7/dist-packages/pyx/path.py", line 1095, in > normpath normpath = normpath([]) > UnboundLocalError: local variable 'normpath' referenced before assignment > > It seems that the problem lies in the fact that there are no less than three > different things being referred to as "normpath" in this method: one of > them is the method itself, one is the normpath class, and one is a local > variable. My interpretation of the situation is that, at line 1095, the > Python compiler sees the assignment and determines that normpath must be a > local, immediately forgetting that there is a definition for the normpath > class, and so the attempt to then call the "normpath" class constructor > fails because Python thinks you're attempting to call the "normpath" local > which hasn't been assigned yet. > > See also http://stackoverflow.com/a/9264845 for a related explanation of > this. > > Renaming the local "namepath" to "np" seems to have solved that issue for > me. > > Finally (after a couple of other hiccups to do with forgetting I was using > the x2 axis, and incorrectly scaling my data - entirely my fault) I've hit > a snag with the paths handling when clipping fluctuating data: things go > obviously wrong. For example, take Joerg's mini2.py. Add an import math, > replace the model function with 100*math.sin(5*x), and then add min=-90, > max=90 to the definition of the y axis. > > It's hard to describe what's happening, except that it looks like the paths > have gotten mangled and are skipping points, so the filled area has large > blocks outside the correct region filled, and has not filled those places > where it should. I confess I'm at a loss for how to proceed from here. Any > ideas? > > Oh, and I'm also looking for a way to hide the confidence region lines from > the generated key, if anyone has any suggestions. > > Thanks, > Brendon > > On August 30, 2013 16:56:23 Joerg Lehmann wrote: > > And here's the attachment :) > > > > On 30.08.13, André Wobst wrote: > > > Hi, > > > > > > I like the code, and I think it is a useful example. So yes, I agree, it > > > is a good example or gallery contribution. I'm slightly addicted to make > > > it an example. > > > > > > Regarding the issue with the decorated path not being stroked nor > > > filled, > > > the solution is rather simple. You can set the lineattr to None to skip > > > stroking. This is a common way to turn off an output in the graph while > > > all work related to generating the output is still in place (thus the > > > path for the line is still generated). > > > > > > I favor to keep the error in the decorated path. While I could slightly > > > simplify some graph code, it is still strange to draw a path without > > > actually creating output. In addition, would this "output" still > > > contribute to the bounding box or not?! And last but not least, take the > > > regular user, who might accidentally call draw without a stroke or fill > > > decorator. I prefer to raise an error for that case. This code was > > > written with Jörg and me together (IIRC), and I'm pretty sure we > > > discussed the pro and contra and putted the exception on purpose in the > > > end. > > > > > > Best, > > > > > > > > > André > > > > > > Am 30.08.2013 um 12:00 schrieb Joerg Lehmann: > > > > Hi Michael, > > > > > > > > First of all, I think this is something that would also be useful for > > > > the examples or the gallery. > > > > > > > > Your code can be simplified a bit though, because the << operator > > > > (respectively PS/PDF) will add straight lines automatically and the > > > > closepath is automatically done while filling. > > > > > > > > Concerning the second graph: We should find a way that this is not > > > > necessary. In principle, there already is deco.stroked.clear, which > > > > prevents stroking of the path. See my attached new version. > > > > > > > > However, this currently does not work because PyX will complain about > > > > the fact that the path is neither stroked nor filled. This is an > > > > explicit check, we could remove (see line 237 in the latest > > > > pyx/deco.py). André, what do you think? > > > > > > > > Cheers, > > > > > > > > Jörg > > > > > > > > On 29.08.13, Michael SCHINDLER wrote: > > > >> Hello Néstor, > > > >> > > > >> On 28/08/13, Néstor Espinoza wrote: > > > >>> I'm trying to draw confidence bands around some model data-points > > > >>> that > > > >>> I > > > >>> have and I think the tutorials that I've read so far that paint > > > >>> areas > > > >>> below > > > >>> curves are not what I'm looking for (e.g., > > > >>> http://pyx.sourceforge.net/gallery/graphs/integral.html), because in > > > >>> order > > > >>> to paint areas between curves with those methods (i.e., by the > > > >>> method > > > >>> suggested in this same mailist here: > > > >>> http://osdir.com/ml/python.pyx.users/2008-07/msg00002.html), the > > > >>> trick > > > >>> is > > > >>> to paint white below the second curve. > > > >> > > > >> I am not quite sure to understand what you want to do. If it is just > > > >> to visualize the confidence of the data, you could use simple error > > > >> bars (http://pyx.sourceforge.net/examples/graphstyles/errorbar.html). > > > >> I you want it more fancy with a shaded area, the principle is the > > > >> same > > > >> as in the integral example: You take out the paths from the graph, > > > >> and > > > >> those can be manipulated (glued together, split, ...). If this latter > > > >> step makes problems, have a look at the joint example. > > > >> > > > >>> Basically in my code I have three vectors, model, model_down and > > > >>> model_up. > > > >>> The idea is to plot the confidence bands between the curves > > > >>> model_down > > > >>> and > > > >>> model_up (which represent my confidence bads) and plot model as > > > >>> datapoints > > > >>> on top: do you have any idea on how to do this? > > > >> > > > >> Best, > > > >> > > > >> Michael > > > >> > > > >> import sys, os > > > >> sys.path.insert(0, os.path.expanduser("~/python/PyX-0.12.1")) > > > >> import pyx > > > >> print pyx.version.version # need 0.12 for canvas layers > > > >> from pyx import * > > > >> > > > >> N = 30 > > > >> xs = [10.0 * i/(N-1) for i in range(N)] > > > >> model = [(x-3)*(x-5)*(x-7) for x in xs] > > > >> model_upp = [y + 10 for y in model] > > > >> model_low = [y - 10 for y in model] > > > >> > > > >> g = graph.graphxy(width=10, > > > >> > > > >> x=graph.axis.linear(title="$x$"), > > > >> y=graph.axis.linear(title="$y$")) > > > >> > > > >> g.plot(graph.data.values(x=xs, y=model)) > > > >> # we need another (identical) graph to avoid plotting lines around > > > >> the > > > >> confidence area: h = graph.graphxy(width=10, > > > >> x=graph.axis.linkedaxis(g.axes["x"]), > > > >> y=graph.axis.linkedaxis(g.axes["y"])) dupp = > > > >> h.plot(graph.data.values(x=xs, y=model_upp), [graph.style.line()]) > > > >> dlow = h.plot(graph.data.values(x=xs, y=model_low), > > > >> [graph.style.line()]) h.doplot() > > > >> > > > >> upp = dupp.path.reversed() > > > >> low = dlow.path > > > >> x0, y0 = low.atend() > > > >> x1, y1 = upp.atbegin() > > > >> connect1 = path.line(x0, y0, x1, y1) > > > >> > > > >> area = low << connect1 << upp > > > >> area.append(path.closepath()) > > > >> > > > >> g.layer("filldata").draw(area, [deco.filled([color.gray(0.8)])]) > > > >> g.writePDFfile("mini") > > > >> > > > >> > > > >> --------------------------------------------------------------------- > > > >> -- > > > >> ------- Learn the latest--Visual Studio 2012, SharePoint 2013, SQL > > > >> 2012, more! Discover the easy way to master current and previous > > > >> Microsoft technologies and advance your career. Get an incredible > > > >> 1,500+ hours of step-by-step tutorial videos with LearnDevNow. > > > >> Subscribe today and save! > > > >> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg. > > > >> cl > > > >> ktrk > > > >> > > > >> _______________________________________________ > > > >> PyX-user mailing list > > > >> [email protected] > > > >> https://lists.sourceforge.net/lists/listinfo/pyx-user > > > > > > > > <mini2.py>------------------------------------------------------------ > > > > -- > > > > ---------------- Learn the latest--Visual Studio 2012, SharePoint > > > > 2013, > > > > SQL 2012, more! Discover the easy way to master current and previous > > > > Microsoft technologies and advance your career. Get an incredible > > > > 1,500+ hours of step-by-step tutorial videos with LearnDevNow. > > > > Subscribe today and save! > > > > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.c > > > > lk > > > > trk_______________________________________________ PyX-user mailing > > > > list > > > > [email protected] > > > > https://lists.sourceforge.net/lists/listinfo/pyx-user > > > > > > ------------------------------------------------------------------------ > > > -- > > > ---- Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, > > > more! Discover the easy way to master current and previous Microsoft > > > technologies and advance your career. Get an incredible 1,500+ hours of > > > step-by-step tutorial videos with LearnDevNow. Subscribe today and save! > > > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clk > > > tr > > > k > > > > > > _______________________________________________ > > > PyX-user mailing list > > > [email protected] > > > https://lists.sourceforge.net/lists/listinfo/pyx-user ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk _______________________________________________ PyX-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pyx-user
