Function Repository Resource:

PlotVector

Source Notebook

Plot a list of vectors in the plane

Contributed by: Dennis M Schneider

ResourceFunction["PlotVector"][{{x1,y1},{x2,y2},}]

plots the vectors {xi,yi}, each located at the origin.

ResourceFunction["PlotVector"][{{x1,y1},{x2,y2},},{p,q}]

plots the vectors {xi,yi}, each located at the point {p,q}.

ResourceFunction["PlotVector"][{{{x1,y1},{p1,q1}},{{x2,y2},{p2,q2}},}]

plots the vectors {xi,yi} located at the corresponding points {pi,qi}.

ResourceFunction["PlotVector"][{{x1,y1},{x2,y2},},{{p1,q1},{p2,q2},}]

plots the vectors {xi,yi} located at the corresponding points {pi,qi}.

Details and Options

ResourceFunction["PlotVector"] accepts the following options:
"ArrowSize"Mediumspecify the size of the arrowhead
"LocatedVector"Falsewhether to draw vectors from the initial point (the first point of the list) to the terminal point (the second point in the list)
VectorStyleRGBColor[.3,.4,.7]specify the style of the vector

Examples

Basic Examples (5) 

Plot the vector (1,1) located at the origin:

In[1]:=
ResourceFunction["PlotVector"][{{1, 1}}]
Out[1]=

Plot a list of vectors located at the origin:

In[2]:=
ResourceFunction["PlotVector"][{{1, 1}, {2, -1}}]
Out[2]=

Plot the vector (2,1) located at the point (-1,1):

In[3]:=
ResourceFunction["PlotVector"][{{2, 1}}, {-1, 1}, AxesOrigin -> {0, 0}]
Out[3]=

Plot a list of vectors located at the point {1,2}:

In[4]:=
ResourceFunction["PlotVector"][{{1, 1}, {2, -1}}, {1, 2}, AxesOrigin -> {0, 0}]
Out[4]=

Plot a list of vectors located at different points. The first list is a list of vectors and the second is a list of initial points:

In[5]:=
ResourceFunction[
 "PlotVector"][{{1, 1}, {2, -1}, {1, .5}}, {{0, 0}, {3, 5}, {2, 2}}]
Out[5]=

Scope (1) 

Specify a vector located at a point in three different ways:

In[6]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/928e33e1-0568-4453-8137-198bba08a990"]
Out[6]=

Options (6) 

ArrowSize (2) 

The default arrow size is Medium, which corresponds (roughly) to "ArrowSize"1.5:

In[7]:=
GraphicsRow[{ResourceFunction["PlotVector"][{{1/2, 1}, {1, 1}}, "ArrowSize" -> 1.5], ResourceFunction["PlotVector"][{{1/2, 1}, {1, 1}}]}]
Out[7]=

Change the arrow size of each vector:

In[8]:=
ResourceFunction["PlotVector"][{{1/2, 1}, {1, 1}}, "ArrowSize" -> {Medium, Large}]
Out[8]=

LocatedVector (2) 

A located vector from the first point to the second point:

In[9]:=
ResourceFunction["PlotVector"][{{1, 1}, {2, -1}}, "LocatedVector" -> True, AxesOrigin -> {0, 0}]
Out[9]=

Setting the located vector to False draws the vectors located at the origin:

In[10]:=
ResourceFunction["PlotVector"][{{1, 1}, {2, -1}}, "LocatedVector" -> False, AxesOrigin -> {0, 0}]
Out[10]=

A list of lists of pairs of vectors with the option "LocatedVector"True draws located vectors from the first point in each sublist to the second point in each sublist:

In[11]:=
ResourceFunction["PlotVector"][{{{2, 1}, {1, -1}}, {{1, 1}, {2, 1}}}, "LocatedVector" -> True, AxesOrigin -> {0, 0}]
Out[11]=

Without the option being set, the second tuple in each list gives the located point, and the first tuple gives the direction:

In[12]:=
ResourceFunction["PlotVector"][{{{2, 1}, {1, -1}}, {{1, 1}, {2, 1}}}, "LocatedVector" -> False, AxesOrigin -> {0, 0}]
Out[12]=

VectorStyle (2) 

Change the style of the vectors:

In[13]:=
ResourceFunction[
 "PlotVector"][{{{3, 1}, {1, 1}}, {{2, -1}, {1/2, 0}}}, VectorStyle -> {{Red, Thick}, Dashed}, AxesOrigin -> {0, 0}]
Out[13]=

Set both the arrow size and style for each vector:

In[14]:=
ResourceFunction[
 "PlotVector"][{{{3, 1}, {1, 1}}, {{2, -1}, {1/2, 0}}}, VectorStyle -> {{Red, Thick}, Dashed}, "ArrowSize" -> {Large, Medium}, AxesOrigin -> {0, 0}]
Out[14]=

Possible Issues (1) 

The length of the list of vectors must be the same as the length of the list of initial points:

In[15]:=
ResourceFunction[
 "PlotVector"][{{1, 1}, {2, -1}, {1, .5}}, {{0, 0}, {1, 1}}]

Publisher

Dennis M Schneider

Version History

  • 1.0.0 – 28 August 2019

Related Resources

License Information