The ability to rotate annotation textboxes is not available in MATLAB 7.9 (R2009b). It is possible to rotate the child text object of the annotation box but not the entire annotation box.
As a workaround, you can either use a text object or a textarrow annotation in place of the textbox annotation, as shown in the following examples:
plot(1:10)
h=annotation('textarrow',[0.5 0.5],[0.5 0.5],'string','textarrow annotation', ...
'HeadStyle','none','LineStyle', 'none', 'TextRotation',90);
set(gca,'Ylim',[0 6],'Xlim',[0 8]);
As an alternative, when creating a text object using the TEXT function, recalculate the position of the object when changing the axes limits:
figure
plot(1:10)
tx=6;
ty=5;
text(tx,ty,'text textbox','Rotation',90);
figure
plot(1:10)
h=text(tx,ty,'text textbox','Rotation',90);
xl=get(gca,'Xlim');
yl=get(gca,'Ylim');
newxl=[0 6];
newyl=[0 8];
scalex = diff(newxl)/diff(xl);
scaley = diff(newyl)/diff(yl);
pos = get(h, 'Position');
tx = pos(1);
ty = pos(2);
offsetx = tx-xl(1);
offsety = ty-yl(1);
set(gca,'Xlim',newxl,'Ylim',newyl);
set(h, 'Position', [newxl(1)+offsetx*scalex newyl(1)+offsety*scaley]);
Best Answer