MATLAB: I have a ‘text’ object on the plot, how can I make it vertical or rotated at any other angle

anglehandleMATLABplotrotatetext;vertical

Consider the following MATLAB code to create a plot with a 'text' object:
x = 0:pi/20:2*pi;
y = sin(x);
plot(x,y)
text(pi,0,'\leftarrow sin(\pi)')
Is there some way to make the text 'vertical' or rotated at any otherĀ angle, instead of 'horizontal'?

Best Answer

Yes, you can do this by modifying the 'Rotation' property of the text object's handle.
Please take a look at the following MATLAB code for an illustrative example:
x = 0:pi/20:2*pi;
y = sin(x);
plot(x,y);
% create some text objects on the plot and get there 'handles'
t = text(pi,0,'\leftarrow sin(\pi)');
t1 = text(1,0,'text1');
t2 = text(2,0,'text2');
t3 = text(5,0,'text3');
% Specify rotation angles for the 'text' object handles
t.Rotation = 90;
t1.Rotation = 30;
t2.Rotation = 180;
t3.Rotation = 45;