auto range limits for spines: please kick the tires

I have implemented something I'm calling "smart bounds" for the axis
spines, and have just committed it to svn r8048. I modified
examples/pylab_examples/spine_placement_demo.py to illustrate the basic
idea -- the spines and ticks should be able to automatically limit
themselves to the data range. There are some subtleties beyond that in
terms of the algorithmic details, but I think if you update from svn and
play around with the demo, especially by panning and zooming in the
figures, you'll get an idea of what I've done. I've attached two images
from such a session.

The key API addition is this:

  spine.set_smart_bounds(True)

Doing so turns on the smart bounds mode in the spine and the axis.

Anyhow, I'd be happy to receive any feedback on this new feature.

-Andrew

noisy_sine.png

spine_demo2.png

This looks nice Andrew,
I haven't tried it, but I wonder whether it's possible to add a keyword arg to suppress the 0's at the origin which are cut through by the axes in the zeroed case (and/or possibly shift the 0 on the horizontal axis left). The same thing is happening in the (1,2) case on the vertical axis.

Gary

Andrew Straw wrote:

···

I have implemented something I'm calling "smart bounds" for the axis
spines, and have just committed it to svn r8048. I modified
examples/pylab_examples/spine_placement_demo.py to illustrate the basic
idea -- the spines and ticks should be able to automatically limit
themselves to the data range. There are some subtleties beyond that in
terms of the algorithmic details, but I think if you update from svn and
play around with the demo, especially by panning and zooming in the
figures, you'll get an idea of what I've done. I've attached two images
from such a session.

The key API addition is this:

  spine.set_smart_bounds(True)

Doing so turns on the smart bounds mode in the spine and the axis.

Anyhow, I'd be happy to receive any feedback on this new feature.

-Andrew

Gary Ruben wrote:

This looks nice Andrew,
I haven't tried it, but I wonder whether it's possible to add a keyword arg to suppress the 0's at the origin which are cut through by the axes in the zeroed case (and/or possibly shift the 0 on the horizontal axis left). The same thing is happening in the (1,2) case on the vertical axis.

Hi Gary,

John also suggested something like this. I don't think it's impossible, but it's outside the scope of the work I have done and beyond my immediate familiarity with the code base. I think it would involve looking at the tick label bounding boxes, finding overlaps, and then deciding which label was less important and removing it. I don't think it would be impossible, and maybe not even hard, but I haven't investigated at all. Thanks for keeping it on the queue.

-Andrew

One easy-ish approach would be to do this at the Axes layer, which
knows all the Axis contained within. We could have some property like
hide_tick_overlaps and have a zorder on the axis, so if an axis is
"above" another, and any of the "lower" axis ticks overlap any of the
above ticks, then the lower ticks would be rendered invisible giving
the user some control of which get shown. This would probably need to
be a draw time operation, with something like a before_draw_hook
handling the visibility and an after_draw_hook restoring the default
visibility.

···

On Mon, Dec 21, 2009 at 3:46 PM, Andrew Straw <strawman@...36...> wrote:

John also suggested something like this. I don't think it's impossible,
but it's outside the scope of the work I have done and beyond my
immediate familiarity with the code base. I think it would involve
looking at the tick label bounding boxes, finding overlaps, and then
deciding which label was less important and removing it. I don't think
it would be impossible, and maybe not even hard, but I haven't
investigated at all. Thanks for keeping it on the queue.

Andrew Straw wrote:

Gary Ruben wrote:
  

This looks nice Andrew,
I haven't tried it, but I wonder whether it's possible to add a keyword arg to suppress the 0's at the origin which are cut through by the axes in the zeroed case (and/or possibly shift the 0 on the horizontal axis left). The same thing is happening in the (1,2) case on the vertical axis.
    

Hi Gary,

John also suggested something like this. I don't think it's impossible, but it's outside the scope of the work I have done and beyond my immediate familiarity with the code base. I think it would involve looking at the tick label bounding boxes, finding overlaps, and then deciding which label was less important and removing it. I don't think it would be impossible, and maybe not even hard, but I haven't investigated at all. Thanks for keeping it on the queue.

I did something like this for the Sage project, but I did it on the tick formatter level. I just made a tick formatter that omitted specified positions. I've attached the "Selective Formatter" class. If anyone has comments, I'd appreciate them! Basically, I just replaced the formatter with the selective formatter, which passed things on to the previous formatter if the tick label was allowed.

It would be great if spines supported this sort of thing natively, but the flexibility of tick formatters seems like a nice place to handle it as well.

Thanks,

Jason

selective_formatter.sage (2.87 KB)