File Exchange

image thumbnail


version 5.18.1 (413 KB) by Tom Davis
Draws lines with directional arrowheads.


Updated 08 Aug 2020

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

ARROW3(P1,P2) draws lines from P1 to P2 with directional arrowheads. P1 and P2 are either nx2 or nx3 matrices. Each row of P1 is an initial point, and each row of P2 is a terminal point.

ARROW3(P1,P2,S,W,H,IP,ALPHA,BETA) can be used to specify properties of the line, initial point marker, and arrowhead. Type "help arrow3" at the command prompt for more information

What's new in Version 5:

All arrowhead and initial point marker sizes (W, H, and IP) are relative to the PlotBox diagonal.

Version 5 attempts to preserve the appearance of existing axes. In particular, ARROW3 will not change XYZLim, View, or CameraViewAngle. ARROW3 does not, however, support stretch-to-fill scaling. If a particular aspect ratio or variable limit is required, use DASPECT, PBASPECT, AXIS, or XYZLIM commands before calling ARROW3. Users are encouraged to report problems directly to the author.

Cite As

Tom Davis (2021). Arrow3 (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (102)

Thomas Dixon

Please completely ignore my previous question

Christopher Willman

Tom Davis

Hello, Mnar --
To use arrow3, the MATLAB current folder or MATLAB path must contain the file, arrow3.m. Please contact me through my MATLAB profile if you still have questions.

Mnar Hmdy

what I should do after downloading arrow3 tool? I have moved the file into R2016a yet I did not work for me, I keep getting the same error " arrow3 is unsigned function". help plz!

Xingwang Yong

Awesome, thank you!

Tom Davis

RE: UI Graphics in App Designer

14 Aug 2020 Joao De Lazzari
28 Mar 2019 Mike Potter

In R2020b, arrow3 works with the HandleVisibility property. In the tutorial, appdesigner.internal.application.openTutorial('BasicCoding'), for example, add the following to function AmplitudeSliderValueChanged(app, event).

value = app.AmplitudeSlider.Value;
plot(app.UIAxes, value*peaks)
app.UIAxes.YLim = [-1000 1000];
app.UIFigure.HandleVisibility = 'on';
figure(app.UIFigure); % set current figure
axes(app.UIAxes); % set current axes
hold on
arrow3([0,-750],[value/2 - 0.01,-750],[],value/50)
hold off
app.UIFigure.HandleVisibility = 'off';

For earlier releases, arrow3 can be modified to accept figure and axes parameters.

function hn=arrow3(p1,p2,s,w,h,ip,alpha,beta,ax,fig)
% fig=gcf; ax=gca;
plot3(ax, ... ) % all instances
surface(ax, ... ) % all instances

Joao De Lazzari

Tom Davis

Hello, Joao --
Is this related to Mike Potter's 28 Mar 2019 comment below? I confess that my reply may have been less than helpful. (I was very pleased with myself until all hell broke loose with R2019b.)

For the first time in many years, I have a recent version of MATLAB, and I would be interested in investigating how Arrow3 might support newer UI features. Please contact me via my MATLAB profile. Thanks.

Joao De Lazzari

Hello Tom,

First of all, the Arrow3 function is awesome! Thanks for sharing with us.
However I am having problems with plotting the arrows in a specific figure plot. Since I am using the AppDesigner, I have several figure axis plots to choose, and I must choose one when using Arrow3. But the function seems not to show this option yet (I am sorry if I am wrong about it).
There is any away that I can do this easily?

Best Regards

Tom Davis

Version 5.18.1 addresses ColorOrder and LineStyleOrder changes in R2019b. This version has fewer problems but still suffers from some issues, particularly with regard to Update capabilities. More fixes will follow.

Tom Davis

Hello, Chris --
Arrow3 takes its name from MATLAB functions like plot3, bar3, pie3, fill3, quiver3, etc. The arrowheads, initial point markers, and cones are always 3D surfaces. Using 2D coordinates will produce a 3D plot in the x-y plane with a 2D view.

Chris Jennings

Tom, It seems any arrow3 command turns a 2D plot into 3D. Not a big problem, but is this a fact of life when using arrow3 ? The help file implies using 2D coordinates will produce a 2D plot.
For example, even if I remove plot3() from your 19 June example it still outputs a 3D plot:
p = 2*[rand(15,1), rand(15,1)];
plot(p(:, 1), p(:, 2), 'k.', 'MarkerSize', 15)
axis equal, hold on
plot(p(1:10, 1), p(1:10, 2), 'r.', 'MarkerSize', 30)
%plot3(p(1:10, 1), p(1:10, 2), ones(10,1), 'r.', 'MarkerSize', 30)
arrow3(p(1, 1:2), p(2, 1:2), '-b2', 2, 3)
hold off

Tom Davis

Hello, Cameron --
Can you please contact me through my MATLAB profile and include your data with an example script? Thanks.

Cameron Kratt

Hello Tom,
I'm having an issue with adding a legend to plots with arrows from arrow3. The legend picks up the line and the arrowhead as an entity, so since I have three arrows plotted, there are six entries in the legend. Three are regular lines, and three are the thicker blocks. Is there a way to fix this?

Taco Broerse

Hello Tom,

Me again. I stumbled upon something else (in 2D again). I found that the line from an arrow overlays the tip of the arrowhead. So the arrowhead is not sharp, but has a line end. I solved this by reducing the line length, depending on the arrowhead length (hacking the code).


Tom Davis

Hello, Taco --
Your first comment does not appear in Comments and Ratings. I repeat it here for reference.

"Nice function. I stumbled upon something that I do not fully understand. When using in 2D, I have that other lines (plotted prior to arrow3) overlay the arrow heads (not fully, but just somewhere halfway the arrow head). I did not touch the alpha value. Any ideas what goes on?"

Arrow3 5.17 specified renderer, Zbuffer, for plots without explicit z coordinates.

"[Zbuffer] renders only those pixels that are visible in the scene (thus eliminating front-to-back sorting errors)."

But Zbuffer is now deprecated, and Arrow3 5.18 uses the Opengl renderer for all plots.

"The OpenGL renderer displays objects sorted in front to back order, as seen on the monitor. Lines always draw in front of faces when at the same location on the plane of the monitor."

So your solution ("This issue seems to be solved when adding a positive z-coordinate.") is a good workaround.


Hello, Chuan --
See comments to and from Taco dated 19 Jun 2020, re renderers. Following code consistently plots red points on top of black points. Note that arrow3 is called last.

p = 2*[rand(15,1), rand(15,1)];
plot(p(:, 1), p(:, 2), 'k.', 'MarkerSize', 15)
axis equal, hold on
plot3(p(1:10, 1), p(1:10, 2), ones(10,1), 'r.', 'MarkerSize', 30)
arrow3(p(1, 1:2), p(2, 1:2), '-b2', 2, 3)
hold off

Taco Broerse

This issue seems to be solved when adding a positive z-coordinate.

Tom Davis

Hello, Linjiang --
The following assumes that z1 (size) is the cone width. By EdgeColor (z3), you likely mean the cone outline in 2D, but arrow3 cones are always 3D surfaces with 21 (0:20) faces. Hence, outlining cannot be achieved with EdgeColor. This code produces a cone plot that responds to colormap changes:

p1 = p(:,1:2);
heading = pi*p(:,3)/180;
p2 = [sin(heading), cos(heading)];
h = arrow3(p1,p2,[],p(:,4),[],'cone');
% Change truecolor CData to colormap values.
c = p(:,5);
for n = 1:length(c)

Tom Davis

Hello, Pedro --
As documented in the Overview above, "If a particular aspect ratio or variable limit is required, use DASPECT, PBASPECT, AXIS, or XYZLIM commands before calling ARROW3." The reason for this is that ARROW3 draws surfaces that look like right circular cones and spheres no matter the aspect ratio, but the ratio must be fixed, and changing that ratio will distort the surfaces.

Pedro Busc

[bug] It seams that arrow3 fixes the axis limits for some reason.

zhao chuan

Hi, I have used arrow3 for a long time, when I used it in matlab r2014b and r2017b, it's ok, there is no problem. However, when I used the same code in r2019b, the result is not the same as before and it's wrong. For example,
figure, plot(p(:, 1), p(:, 2), 'k.', 'MarkerSize', 15);axis equal, hold on,
arrow3(p(1, 1:2), p(2, 1:2), '-b5', 0.2, 0.3);hold on,
plot(p(1:10, 1), p(1:10, 2), 'r.', 'MarkerSize', 20);
although point size in the second plot is larger than in the first plot, the black dots can't be covered by the red color set in the second plot.

Jiazhen Leng

li linjiang

Hello Tom
we hope to draw cones with colormap. Do you have any example of this? Example 2 and Example 6 work together( For example, we have data with 5 rows:x,y,heading angle, z1,z2.
x and y denote are the coordinate, heading angle is the direction, z1 denotes the size, z2 denotes the color, which should use colormap. (It would be better if we have additional raw z3 to control the EdgeColor)Can you help me, follow is our data:
115.700 21.600 111.415 1.051 0.892
116.600 22.800 74.331 0.848 0.151
115.300 23.100 49.346 0.826 0.133
114.400 23.000 16.858 0.798 0.168
116.400 21.000 118.786 0.501 0.274
116.500 22.000 94.239 0.502 0.245
116.700 22.900 72.636 0.509 -0.198
115.300 20.100 152.103 1.247 0.249
113.900 20.200 186.223 1.244 0.412
112.700 20.500 218.671 1.244 0.359
112.000 21.000 239.609 1.237 0.119
115.300 20.100 152.103 1.298 0.947
114.100 20.300 180.858 1.278 0.865
113.100 20.400 208.520 1.253 0.561
112.400 20.300 220.937 1.228 -0.285
114.300 19.700 176.306 1.056 0.514
114.100 20.400 180.905 1.050 0.547
113.700 21.200 202.261 1.047 0.804
113.200 22.100 264.870 1.048 0.504
112.900 22.500 285.943 1.043 0.348

Islam Elgamal


Tom Davis

Hello, Allen --
As documented in the Overview above, and consistent with PLOT3, "P1 and P2 are either nx2 or nx3 matrices. Each row of P1 is an initial point, and each row of P2 is a terminal point." If column vectors are more convenient, you can transpose them, e.g. arrow3([0;0;0]',[1;1;1]').

Alan Peters

This only works if the start and end vectors are rows (1x3). Given 2 column vectors, it returns 'Invalid input, type HELP ARROW3 for usage examples '

Tom Davis

Hello, Chris --
Version 5.17 does not adequately address the line color issue. I will post an interim fix that I hope will meet most needs, but the code still has a lot of problems. Arrow3 makes extensive use of the ColorOrder property, and that property has changed fundamentally in 2019b.

Chris Jennings

I've been using arrow3 for some time, but suddenly I cannot control line colors. For example:
used to produce light grey arrows, but now they are blue.
(Also happens for my older scripts that used to work fine)
I'm using MATLAB 2019b
Is anyone else experiencing this?

Christian Krogh

Tom Davis

Hello, Li --
It is most likely that the problem is the position of the last line of code. From the Overview above, "If a particular aspect ratio or variable limit is required, use DASPECT, PBASPECT, AXIS, or XYZLIM commands before calling ARROW3." See also arrow3_messes_up_my_plots.html in

Tom Davis

Hello, Li --
I do not have wind.dat. Please contact me through my MathWorks profile, and we'll sort it out.

li linjiang

First, I use quiver to get P1 and P2 of the arrows. Then I use Arrow3 to draw the arrows. I found that the base of the head is not perpendicular to the line. Can you please help me to solve this. My code is as follows:
u =data(:,3);
v =data(:,4);

%// Taken from "quiver.m". Computes autoscale
if min(size(x))==1, n=sqrt(numel(x)); m=n; else [m,n]=size(x); end
delx = diff([min(x(:)) max(x(:))])/n;
dely = diff([min(y(:)) max(y(:))])/m;
del = delx.^2 + dely.^2;
if del>0
len = sqrt((u.^2 + v.^2)/del);
maxlen = max(len(:));
maxlen = 0;
if maxlen>0
autoscale = 0.9 / maxlen;
autoscale = 0.9;

%// quiver plot
quiver(x, y, u, v)
axis([1 28 -1.5 1.5]), daspect([8 2 1])


Debasis Mohapatra

Tom Davis

Version 5.17 addresses line color issues introduced in R2019b.

Cuneyt Aydin

Thank you for this function. Please rate after reading the examples in html in zip of this download.

Tom Davis

Thank you for the bug report, David.

There is no intentional mechanism to set arrowhead color independent of line color. I believe the line color issue is related to new color and line style features in R2019b. I have made preliminary changes to the code that support single-colored lines and arrows, e.g. your example, but multicolored lines and arrows are still a problem. See arrow3_examples.html and attendant images in for examples of intended results.

Contact me through my MathWorks profile, and I will keep you updated as I modify Arrow3.

Cuneyt Aydin

David Brinkmeier

Matlab r2019b: Color specification has no effect on line color
source code indicates line color using plot3 is not set whatsoever - why would I want to set the arrowhead color independent of the line?


yields 3 unit vectors with black arrow heads and blue lines for me, plot3 uses the default color order which I don't want to modify globally

Tom Davis

Hello, Ali --
ALPHA (default = 1) is a vector of FaceAlpha values ranging between 0 (clear) and 1 (opaque). The number of pixels (resolution) does not change with decreasing ALPHA, but the pixels themselves become more transparent.

Ali Aghaeifar

Changing "ALPHA" decreases the resolution of arrows. Why?

Ali Aghaeifar

Tom Davis

Hello, J.P. --
The column vector of decimal values *is* a vector of handles. See comment on 26 Jul 2011 below, re animation.

J. P.

How do you remove arrow3 objects from a figure during a looped animation? For some reason hn = arrow3(p1,p2,...) does not return a vector of handles to line and surface objects. In fact, hn is simply a column vector of decimal values. Any help would be greatly appreciated.

Saurabh Patel

Tom Davis

Hello, Mike --
Arrow3 is 17 years old; it is a testament to MATLAB's backward compatibility that it works at all. Arrow3 always plots to the current figure (gcf) and axis (gca), but it is likely that you can change this behavior by modifying line 349: fig=gcf; ax=gca;

Mike Potter

How do you cause the arrow3 to draw to a particular axis handle? I'm trying to use it in a GUI (a UIaxes), but the function doesn't seem to allow you to direct it to a particular axes. And the command 'axes(...)' doesn't work with UI axis

Roberto Noriega

Bahram Khazaei

Bradley Abell

Is there an easy way to specify which axis to plot the arrows to? I am trying to use in the a matlab app and the axis must be specified.

Renwen Lin

It is great. However. the quality of its emf file is low. BTW: I outport the emf file by "save as".

Ricardo Vega Ayora

Jose Ercolino


Great function, works perfectly for me.
How do I handle this in the legend, though? I have
eq=arrow3(... first set of arrows
lq=arrow3(... second set of arrows
legend([eq lq],'normals from edges','normals from layers')
and it's giving me an error ("Operands to the || and && operators must be convertible to logical scalar values.")

Thanks for any advice!

ritwik chattaraj

yong geng

You're so nice guy~

Subhash Pidaparthi

Thank you Tom

Tom Davis

Hello, Ikem --

Extract the files to a folder, e.g. C:\arrow3.

Then in the MATLAB Command Window:

cd C:\arrow3
help arrow3

Ikem Solomon

Please how do I install it. I am having problems attaching it to my matlab

Tom Davis

Hello, John --

This works for me:

load durer
axis image
hold on
arrow3([235 215],[130 465],'r-2.5',1.5)
hold off

John Peter Davalos

Arrow head not showing if plotted over an image?

Gopal Karemore

Thank you Tom!

Liya Wang

Hello Tom,

Sorry I make a mistake.I mixes up lon and lat.I can draw arrows on worldmap now.You can ignore my question earlier.Thank u very much!

Best wishes.


Liya Wang

Hello Tom,
Thank you for your answer.When I draw 2D arrows,which plotting functions in your code make it work? I just find plot3.Could you please tell me all plotting functions you used in your code .

Tom Davis

Hello, Liya --

I have neither the Mapping Toolbox nor a recent version of MATLAB. If you can ask specific questions, I may be able to help.

Good luck and best wishes.

-- Tom

Liya Wang

hello Tom,I want to ask you a question.When I use the function worldmap and draw arrows on it,I try to modify your code,but I can't.Could you please modify your code so that it can be used on the worldmap.Thank u so much!


Thanks a lot! The function is very useful

Adam Danz

Nice, saved me from a lot of footwork.

tao song

I love this .m file.

Andreas J.

sorry i didn't want to submit the last voting. I didn't read the "relative to the PlotBox diagonal" at the time i was about to write a critic, but as i reread the description i closed the tab.

But i still think that this is an annoying feature, i would like it more if i could choose wether it should be relative or a fix size. I also don't like that it clears the axes. I know a workaround but it's still annoying me everytime i have to use arrow3. Just my opinion.

Andreas J.

Daniel Frisch

yang yang

Thanks for your arrow3 program.


Great code. Have been using it for quite a long time.



Tom Davis

Hi, Jonas --

Please try version 5.15. Thanks.

-- Tom


I've downloaded arrow3 sometime in 2002 for the first time; great job, guys!

In order to avoid possible conflicts with other code writing to the 'UserData' property, I suggest replacing these calls by "setappdata(ax,'arrow3',value)"


It does not ignore zero magnitue input (R2012a).

>> arrow3([1 1],[1 1])
Error using arrow3 (line 373)
P1 cannot equal P2

Jeonghyun Seo

Xilu Wang



Hi Tom,

thanks for that nice contribution. I would enjoy if you could modify the input arguments with string propertys (similar to most of the inbuilt-functions (f.e. 'LineWidth', 2)), in particular to add a 'Parent' property to get rid of the problems with multiple axes!


Tom Davis

Hello, Tomazc --

Please try this and write if you have questions. Thanks.

% Animation Example
t=(0:pi/40:8*pi)'; u=cos(t); v=sin(t);
grid on, view(35,25)
hold on
p=[20*t,u,v]; inc=4:1:length(t);
p2=p(inc,:); p1=p(inc-1,:);
for i=2:1:length(p1)
hold off



I'd like to use arrow3 in animation (for function) where only one arrow will be shown, so i cannot use 'hold on'.
In this case the 'axis' are not working, but i need the same view.

Any suggestion?

axis([-400 400 -400 400 -100 700])
whitebg([1 1 1]);
view(35, 25)
grid on

for i = 1:1:15

Sauro Salomoni

Does what it's supposed to do, and the help files are VERY detailed. Thank you very much! :)

Tom Davis

Instead of using Copy Figure from the Edit menu, use Save As from the File menu, save the figure as a PNG file, and then insert the PNG file into Word.

Lei Shang

Very useful with 3D plots. But when I'm copying figures to word, all the nice arrows plotted by 'arrow3.m' disappeared. And my command window displays:

Warning: RGB CData not yet supported in Painter's mode
> In graphics\private\restorehg at 100
In graphics\private\restore at 29
In print at 277
In editmenufcn at 78

How do I fix this?

Lei Shang

Tom Davis

Wide lines may obscure the arrowhead tip, but the line endpoint and arrowhead tip are _always_ coincident.

Philipp Wissgott

On my matlab (R2007a) the line of the arrow is visible after the tip of the arrowhead in 2D plots. It looks like as if the arrowhead is plotted at the wrong position.
In my example arrow3 is called after some calls of "line()" and "rectangle()". I can supply further information if required.

Tom Davis

It is not necessary to set AXIS EQUAL, but commands that may change the aspect ratio should be issued _before_ calling ARROW3. ARROW3 draws surfaces that look like right circular cones and spheres no matter the aspect ratio, but the ratio must be fixed, and changing the ratio will distort the surfaces.

There are many examples in the HTML files that illustrate how to use ARROW3 before and after PLOT, POLAR, CONTOUR, PLOT3, SURF, SLICE, and PATCH.

piao lin

it seems if I want to plot another plot3(......) with arrow3(.....)

I should

hold on;
axis equal ; %you'd better use axis equal

if I put plot3(....) before arrow3(.....) ,just like below ,I get not see the result of arrow3(.....);

hold on;
axis equal ; %you'd better use axis equal

Vaibhav Deshpande

I am doing a project in layup optimization of balanced symmetric laminates, and I wanted to display at each call to fmincon the material direction for my laminate, I was able to so by using arrow3, thank you.

Vaibhav Deshpande.

Georg Stillfried

works fine

dong ding

it's excellent.I can use it to draw my picture. thanks!

Ahmet Sacan

I was happily using arrow.m until I came to see that it for some reason did not draw anything when my m file was deployed (i.e., running executable that resulted from mcc). I came back to File Exchange for a different arrower instead of trying to debug arrow.m. Now I'm using arrow3 which works fine in deployed mode. thanks.

maricel miguel

I havent tried it but looks good from the screen shot, what was the thought process on this one, and how long did it took you

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!