Open In App

MATLAB Annotation

Annotations in MATLAB is a way of adding explanation or notes to the plots. Annotations add more information to the plots. There are different syntax formations for adding annotations to a plot:

Let’s discuss all the above functions in detail:



annotation(lineType,x,y)

Example :




% Plots y = x line from 1 to 10
plot(1:10)
 
x = [0.4 0.6];
y = [0.8 0.6];
 
% annotation with lineType 'arrow'
annotation('arrow',x,y)

Output : 



annotation(lineType)

Example : 




% Plot y = -x from 1 to 10
x = [1:10]
y = -x
plot(x,y)
 
% annotation of lineType 'arrow'
% at default positions
annotation('arrow')

Output : 

annotation(shapeType,dim)

Example : 




% Plot y = x^2 from 0 to 10
x = [0:10]
y = x.*x
plot(x,y)
 
% Dimensions of textbox
dim = [0.2 0.3 0.3 0.3]
str = 'Parabola y = x^2';
 
% Annotation of shapeType 'textbox'
% at "dim" with "str"
% content inside the textbox
annotation('textbox',dim,'String',str);

Output : 

annotation(shapeType)

Example : 




% Plot y = ^2 from 0 to 10
x = [0:10]
y = x.*x
plot(x,y)
 
% Annotation with shapeType='rectangle'
% with default positions
% of rectangle
annotation('rectangle');

Output :

annotation(___,Name,Value)

Example : 




% Plot y = x^3 - 12x from -5 to +5
x = linspace(-5,5);
y = x.^3 - 12*x;
plot(x,y)
 
% Dimensions of eclipse
dim = [.3 .50 .25 .15];
 
% eclipse takes dimensions as it'll
% fit into specified
% rectangle dimension
% Annotation with color , FaceColoe and
% FaceALpha of eclipse
annotation('ellipse',dim,'color','red','FaceColor',
'green','FaceAlpha',.3)

Output : 

 


Article Tags :