In the box plot figure, all text objects are contained in an hggroup. Because all of the objects are grouped, any changes made to the positions will not be saved when the figure is redrawn. To work around this, you regroup the objects after resizing. This can be done as follows:
close all
load carsmall
boxplot(MPG, Origin)
hg1 = get(gca,'Children')
ch2 = findobj(hg1,'type','text')
set(ch2,'Units','data')
set(ch2(1),'Position',[6 10 17.3205])
copyobj(hg1,gca)
delete(hg1);
On the other hand, if you prefer to remove the hggroup entirely, you may do this with the following code:
close all
load carsmall
boxplot(MPG, Origin)
hg1 = get(gca,'Children')
ch = get(hg1,'Children')
set(ch,'Units','data')
copyobj(ch,gca)
delete(hg1)
Please also note the use of the 'Data' value for the 'Units' Property. This ensures that the text objects stay fixed relative to axes locations when the figures are resized.
Best Answer