How do you make a line with an arrow halfway between 2 points?
4 views (last 30 days)
Show older comments
i'm looking for something like. [p1] ------>-----[p2]
0 Comments
Answers (1)
jonas
on 10 Jul 2018
Edited: jonas
on 10 Jul 2018
Let's say you want an arrow from between [X1 X2],[Y1 Y2]. We use annotation but specify the arrow coordinates by the axes coordinates (instead of the default figure coordinates)
x=0:.05:2*pi;
y=sin(x);
h=plot(x,y)
X=[0 4]; %[X1 X2]
Y=[0.5 -0.5]; %[Y1 Y2]
Pos=get(gca,'position');
xlimits=get(gca,'xlim');
xmin=xlimits(1);
xmax=xlimits(2);
AxesRangeX=diff(xlimits)
FigPosX=Pos(1)+(X-xmin)*(Pos(3)/AxesRangeX)
ylimits=get(gca,'ylim');
ymin=ylimits(1);
ymax=ylimits(2);
AxesRangeY=diff(ylimits)
FigPosY=Pos(2)+(Y-ymin)*(Pos(4)/AxesRangeY)
dX=diff(FigPosX);
dY=diff(FigPosY);
annotation('arrow',FigPosX,FigPosY,'headstyle','none')
annotation('arrow',FigPosX-[0 dX./2],FigPosY-[0 dY./2])
2 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!