""" example describing how to get the dimensions of a text (its bounding box)

    remark: The interactive mode and the call 'draw()' are needed in order to
            calculate the appropriate bounding box.
"""

import matplotlib.pyplot as plt

plt.ion()
t = plt.text(0.5, 0.75, "Hello world!")
plt.draw()

print "fontsize is ", t.get_size()
print "fontstyle is ", t.get_fontstyle()

# get the corresponding bounding box:
bbox = t.get_window_extent()
print "bbox is between points", bbox.xmin, bbox.ymin, " and ", \
      bbox.xmax, bbox.ymax

# and the bbox in axes coordinates:
print " and transformed to the realspace coordinates "
ax = plt.gca()
bbox_axes = bbox.inverse_transformed(ax.transAxes)
print "bbox_axes is between points", bbox_axes.xmin, bbox_axes.ymin, " and ", \
      bbox_axes.xmax, bbox_axes.ymax

plt.ioff()
plt.show()
