%% Add Text to Three Data Points on Graph
% This example shows how to add text descriptions with arrows that point to   
% three data points on a graph. 
% 
% Use the |linspace| function to create |t| as a vector of 50 values between   
% 0 and $2\pi$. Create |y| as  sine values. Plot the data. 

% Copyright 2015 The MathWorks, Inc.


t = linspace(0,2*pi,50);
y = sin(t);
plot(t,y)
%% 
% Use the |text| function to add a text description to the graph at the   
% point $(\pi,\sin(\pi))$. The first two input arguments to this function   
% define the text position. The third argument defines the text string. Display   
% an arrow pointing to the left by including the TeX markup |\leftarrow| in the   
% string. Use the TeX markup |\pi| for the Greek  letter  $\pi$.


x1 = pi;
y1 = sin(pi);
str1 = '\leftarrow sin(\pi) = 0';
text(x1,y1,str1)

%% 
% Add text descriptions to two more data points on the graph. By default,
% the text aligns so that the specified data point is to the left
% of the string. Specify the |HorizontalAlignment| property for the last description
% as |'right'| so that the data point is to the right of the
% string. Use the TeX markup |\rightarrow| to diplay an arrow pointing to
% the right.

x2 = 3*pi/4;
y2 = sin(3*pi/4);
str2 = '\leftarrow sin(3\pi/4) = 0.71';
text(x2,y2,str2)

x3 = 5*pi/4;
y3 = sin(5*pi/4);
str3 = 'sin(5\pi/4) = -0.71 \rightarrow';
text(x3,y3,str3,'HorizontalAlignment','right')
