How can I get the extent (bounding box) of the legend on a plot? For example, can get the extent of a text label like this:
h = text(x, y, "hello");
extent = get(h, 'extent');
I am trying to place text labels where they do not overlap with objects on the plot.