How to plot arrow with data coordinates in Matlab?

后端 未结 8 1886
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 19:37

I know there is a function named annotation can plot arrows or double arrows. But annotation can only plot in normalized unit. For example:

annotation(\'arro         


        
8条回答
  •  無奈伤痛
    2020-12-13 20:12

    One approach would be to define an arrowhead in the axis units:

    Ax=[0 -0.003 0.003 0];       % (Ax,Ay) form an upward pointing arrowhead.
    Ay=[0.01 0.0060 0.0060 0.01];
    Ax=Ax-mean(Ax);  % center it on zero
    Ay=Ay-mean(Ay);
    

    Then at desired arrowhead index in on a curve vv, compute

    x1=vv(in,1); y1=vv(in,2);
    x2=vv(in+1,1); y2=vv(in+1,2);
    u=x2-x1;
    v=y2-y1;
    th=-pi/2+atan2(v,u);
    R=[cos(th) -sin(th); sin(th) cos(th)];   % Rotation matrix for local slope of vv.
    A=R*[Ax;Ay];    % Rotate the arrowhead.
    patch(x1+A(1,:),y1+A(2,:),'r','LineWidth',0.01)   % plot rotated arrowhead at (x1,y1).
    plot(x1+A(1,:),y1+A(2,:),'r','LineWidth',0.01)    % Kludge to make boundary red too (I'm sure there is a more elegant way).
    

    Worked for me, for my particular circumstances.

提交回复
热议问题