Search code examples
matlabplotannotationsfigure

How to plot arrow with data coordinates in Matlab?


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('arrows',[x1 x2],[y1 y2])

Here, [x1, x2] should be a ratio number less than one.

So, my question is how can I plot arrows with a true value rather than a normalized value?

I wonder if there is any other function can approach this or is there any function I can get the axis value of the figure so that I can adjust the true value into a normalized value.


Solution

  • I've just discovered this method, since I don't want to have to bother with normalised units. Use the latex interpreter:

    figure
    plot([1:5],[1:5]*3,'.-')
    %// Say I want to put an arrow pointing to the location, [3 9]    
    text(2.94,8.3,'\uparrow','fontsize',20)
    text(2.8,7.8,'point [3,9]')
    

    To make the arrow longer, use a larger fontsize.

    Pros

    • Easier, faster and quicker than using normalised units
    • Don't need to install any functions (good for us lazy people..)
    • making use of the LaTeX interpreter, there is a whole range of arrows (up, down, left, right and other angles (see Symbol list)

    Cons

    • Definitely needs trial and error/tweaking to get the correct location of the arrow head relative to the POI.
    • There is limited control over the length of the arrow
    • Some latex commands aren't understood by the interpreter (boo).