get bboxes of bars in data coordinates

I need to get the bboxes for time-range bars (matplotlib.patches.Rectangle objects) on a bar plot for a custom autoscaling function.

Right now, I get them like this, where rectObj = a bar and bboxes = a list of bboxes:

bboxes.append(rectObj.get_path().get_extents())
print 'bboxes is: ', bboxes

However, the print shows bboxes to be:

bboxes is: [Bbox(array([[ 0., 0.],
[ 1., 1.]])), Bbox(array([[ 0., 0.],

   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],
   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],
   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],
   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],
   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],

   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],
   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],
   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],
   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],
   [ 1.,  1.]])), Bbox(array([[ 0.,  0.],

   [ 1.,  1.]]))]

This is not what I need, because these points have nothing to do with the y axis I’m scaling (in fact, what do they mean?). Instead, I need bboxes that look more like this:

bboxes is: [Bbox(array([[ 734190.02541214, 730844.29166667],

   [ 734223.88252666,  730844.375     ]]))]

(Although this is from getting the bboxes from a line, not a set of bars)
These are in the floating point version of a date, which is what the y axis is scaled in. How can I get the bboxes of these bars in those coordinates?

Thanks,
Che

I should add, I can see that (I think) this needs to use a transform to get it in data coordinates, because if I do this to each rectObj (each bar):

trans = rectObj.get_patch_transform()
print 'trans is: ', trans

I get:

trans is: BboxTransformTo(Bbox(array([[ 734189.52541214, 730844. ],
[ 734190.52541214, 730844.33333333]])))

Which shows the data-coordinate bboxes “in there”, but that’s now a BboxTransformTo object, not a Bbox object.

I’m just don’t know what method turns a display-coordinate bbox into a data-coordinate bbox.

Thanks,
Che

OK, I have it… Because I was using the above to get the bbox for a Line2D object, I didn’t realize there was already a method to get the bbox (in data coordinates) from a Rectangle:

rectObj.get_bbox()

-Che

···

On Mon, Mar 28, 2011 at 1:44 PM, C M <cmpython@…287…> wrote:

I need to get the bboxes for time-range bars (matplotlib.patches.Rectangle objects) on a bar plot for a custom autoscaling function.

Right now, I get them like this, where rectObj = a bar and bboxes = a list of bboxes:

bboxes.append(rectObj.get_path().get_extents())
print 'bboxes is: ', bboxes