def textBoxSize(txt, transformation=None, figure=None):
    """Get the width and height of a text object's bounding box transformed to the desired coordinates. Defaults to
    figure coordinates if transformation is None."""

    fig= txt.get_figure() if figure is None else figure
    if transformation is None:
        transformation = fig.transFigure

    coordConvert = transformation.inverted().transform
    bboxDisp = txt.get_window_extent(fig.canvas.renderer)
    bboxConv = coordConvert(bboxDisp)
    w = bboxConv[1,0] - bboxConv[0,0]
    h = bboxConv[1,1] - bboxConv[0,1]
    return w, h