how to allign plot figure and annotation

2 views (last 30 days)
Muhammad Haziq
Muhammad Haziq on 12 Feb 2021
Answered: Vimal Rathod on 19 Feb 2021
Hi,
I wanted to draw annotation to some specific points in a graph but when I plot these annotation they are not allign to the grapgh. I wanted to to allign both x-axis of graph figure and annotation so I can mark my annotation on the correct points with respect to x axis. Can any one help me how can I can allign them.
I am attaching my code and pictures.
Thanks in advance.
Regards,
Haziq

Answers (1)

Vimal Rathod
Vimal Rathod on 19 Feb 2021
Hi,
You could change the position of annotation by changing the X and Y properties of the annotations. These values represent the values relative to the whole figure and the units are normalized.
You could try to assign the "Y" property value of annotation less to make the annotation come down towards X axis and change the "X" property accordingly to make sure the annotation points at the right points.
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
hold on
%ar1 for first annotation
ar1 = annotation('arrow',[0.3 0.3],[0.05 0.1]);
c = ar1.Color;
ar1.Color = 'red';
ar1.HeadStyle = 'plain';
hold on
%ar2 for second annotation
ar2 = annotation('arrow',[0.83 0.83],[0.05 0.1]);
c = ar2.Color;
ar2.Color = 'red';
ar2.HeadStyle = 'plain';
Refer to the following link to know more about the properties of annotations

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!