From: Fernando P. <Fer...@co...> - 2005-02-09 21:48:04
|
John Hunter wrote: > Hmm, seems to work for me -- you didn't specify the colors in your > example which makes it hard to test, so I'll add them Weird. I ran this a ton of times, and in _most_ cases I get your same results. And yet a _few_ times, and only when I pasted the code in an interactive window, the horizontal line ends below the sine/cosine plots. Very, very strange. > Well the zorder kwarg is your friend -- did you see > examples/zorder_demo.py ? Eg > > plot(x,y, zorder=100) # I'm on top! I did read it, but I guess I misunderstood the docstring on top. I understood it as meaning that you could only reorder classes of objects relative to one another (lines, text, patches), but not individual lines within the class of all lines. > Now, if I recall correctly, python sort doesn't guarantee preserving > order for equal element. Since the order in the respective list > (patches, lines, etc) *is* determined by the order of the plot > commands, we might be better off with > > dsu = [ (a.zorder, i, a) for i, a in enumerate(artists)] > dsu.sort() > > for zorder, i, a in dsu: > a.draw(renderer) > > to guarantee relative order for artists with the same zorder. > > Or is sort relative order preserving for equal elements? Well, the funny thing about my sometimes-odd results, is that in python 2.3, list.sort _is_ stable: http://py-stablesort.sourceforge.net/doc/2002_07_28_pythonowns_archive.html http://mail.python.org/pipermail/python-list/2003-April/160326.html So I'm not quite sure why I get odd results in a few cases. And I can't seem to find a reliable way to repeat the behavior. But thanks for the clarification on the zorder argument, that's enough for me to get the behavior I need. I'll update the zorder_demo example with a more explicit docstring so others don't fall into the same confusion. Cheers, f |