How to plot arrow with data coordinates in Matlab?

Even though annotation uses normalized as default units, you can associate these objects to the current axes (gca) and use data units for setting X and Y properties.

Here is an example of plotting a single arrow.

plot(1:10);
ha = annotation('arrow');  % store the arrow information in ha
ha.Parent = gca;           % associate the arrow the the current axes
ha.X = [5.5 5.5];          % the location in data units
ha.Y = [2 8];   

ha.LineWidth  = 3;          % make the arrow bolder for the picture
ha.HeadWidth  = 30;
ha.HeadLength = 30;

enter image description here


For the positioning of annotations, Matlab offers the function dsxy2figxy to convert data space points to normalized space coordinates. However, for whatever reasons, the function is not included in the Matlab distribution and has to be "created" first.

Copy the following line into the command window and execute it to open the function in your editor.

edit(fullfile(docroot,'techdoc','creating_plots','examples','dsxy2figxy.m'))

To use the function dsxy2figxy save it somewhere in your matlab search path.

Please find the full instructions for the function dsxy2figxy at matlab-central: http://www.mathworks.de/help/techdoc/creating_plots/bquk5ia-1.html