MATLAB Answers

How can I rotate a textbox annotation in MATLAB 7.9 (R2009b)?

188 views (last 30 days)
I am looking for a way to create a textbox annotation in a figure in a vertical orientation. I know that it is possible to rotate a TEXT object, however it is not possible to rotate an annotation textbox. I need to fix the text box position with respect to the figure coordinates, therefore, I need to use textbox annotation objects, as the TEXT objects coordinates would change with the axes limits.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 6 Jan 2010
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);
%%now change axes limits - note that the annotation maintains its position
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);
%second figure for comparison
figure
plot(1:10)
h=text(tx,ty,'text textbox','Rotation',90);
%change axes limits and reposition text object accordingly
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]);

  0 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2009b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!