How to get ticks on top of Polygons?

I tried setting the z-order of the tick objects, but it

    > looks to me like the ticks are hard-coded to always draw
    > before (underneath) any lines or patches.

That's right, they are. This is a bug and not a feature :frowning:

The ticks are drawn as part of the Axis. See
matplotlib.axes.Axes.draw, eg

        if self.axison:
            self.xaxis.draw(renderer)
            self.yaxis.draw(renderer)

The Axis instances (XAxis and YAxis) are comprised of Line2D (the
ticks) and Text (the labels) instances.

    > Is there a way to tell the Axes to draw the ticks on top
    > of any Polygons instead of underneath?

As noted above, before any of the zorder sorting is done, the xaxis
and yaxis are drawn. One possible solution is to move the axis
drawing commands to the end of the Axes.draw function. Off the top of
my head, I don't see any problem with this approach. Typically, you
want the ticks visible. We've talked in the past on the dev list
about the desirability in supporting ticking inside, center or outside
the axes box, but it hasn't been implemented yet.

Vis-a-vis zorder sorting, a more general solution would be to have a
method which extracts the Artist primitives (Line2D and Text) from the
XAxis and YAxis and adds them to the sort, but I'm not sure if this is
actually better. In real life, I think you always want them on top.
Right?

    > If not, it doesn't look like it would be too hard to
    > modify Axes.draw() to respect the z-order of ticks. I'm
    > happy to do this, although I'm nervous that it might
    > break stuff that assumes that ticks are always drawn
    > before everything else. John, do you recommend that I
    > create such a mod?

Yes, if you can find something that works, and behaves sanely over the
poorman's unit tests in examples/backend_driver.py.

JDH

I agree. I was thinking that the ticks would have to be dumped into the 'artists' list and drawn in zorder, but it's much easier to just move the x/yaxis draw() calls after the 'artists' draw() calls.

Attached is a patch that does that. I ran the examples/backend_driver.py with it in place and didn't see any problems.

--Michael

axes.py_patch (782 Bytes)

···

On Wed, 13 Apr 2005, John Hunter wrote:

One possible solution is to move the axis
drawing commands to the end of the Axes.draw function. Off the top of
my head, I don't see any problem with this approach. Typically, you
want the ticks visible.

========================================================================
  Michael Brady Phone: 818-354-4957
  Jet Propulsion Laboratory (M/S 301-140L) Fax: 818-393-6388
  4800 Oak Grove Drive
  Pasadena, CA 91109 E-mail: Michael.Brady@...369... ========================================================================