# Plot a vector field over a line

This seemingly simple problem is giving me some trouble. I need to plot a vector field on a line, and for that I'm following what I found here. I try to create a mesh that contains two points and just plot vectors on it:

\[ScriptCapitalD] = MeshRegion[{{0, 1}, {1, 1}}, Line[{1, 2}]];
VectorPlot[{Sin[x], Cos[y]}, {x, y} \[Element] \[ScriptCapitalD]]


But I get the following error:

VectorPlot::idomdim:  does not have a valid dimension as a plotting domain. >>


What's wrong with this approach?

In my opinion the easy way to plot vectors over 1D curve is to used VectorPoints option:

points = Table[{i, 1}, {i, 0, 1, .1}];
VectorPlot[{Sin[x], Cos[y]}, {x, 0, 1}, {y, -1, 2},
VectorPoints -> points, VectorScale -> {0.1, .2},
Epilog -> Point[points]]

• I like your solution. Is there a way to have the tail of the vectors at the points? Jan 16 '16 at 18:07
• Yes you can add 'VectorStyle->"LeftArrow' Jan 16 '16 at 18:27

I don't know how to make this with RegionFunctions but you could show the vectors along the Line[{{0, 1}, {1, 1}}] like this:

VectorPlot[{Sin[x], Cos[y]}, {x, 0, 1}, {y, 0.5, 1.5},
AspectRatio -> 1/5,
FrameTicks -> {True, {0.95, 1, 1.05}, False, False},
GridLines -> {None, {1}},
GridLinesStyle -> {Blue, Dashed},
PlotRange -> {Automatic, {0.95, 1.05}}] Well, here's a way that works when the number of seconds since Jan. 1, 1970 is odd (that is, it crashes the kernel every other time I execute it):

reg = MeshRegion[{{0, 1}, {1, 1.001}}, Line[{1, 2}]];
points = MeshCoordinates@ DiscretizeRegion[reg, MaxCellMeasure -> {"Length" -> 0.1}];
vf = Table[{p, {Sin[x], Cos[y]} /. Thread[{x, y} -> p]}, {p, points}];
ListVectorPlot[vf, VectorPoints -> All,
Frame -> {{False, False}, {True, False}}, AspectRatio -> Automatic] Maybe someone will find a way that doesn't randomly stumble over a bug.

A manual construction that doesn't crash:

vfvec[{p_, v_}, scale_: 1] := Arrow[{p, p + scale*v}];
Graphics[{Arrowheads[0.03], vfvec[#, 0.1]} & /@ vf,
Frame -> {{False, False}, {True, False}}] If you want centered arrows like VectorPlot, then change vfvec to

vfvec[{p_, v_}, scale_: 1] := Arrow[{p - scale*v/2, p + scale*v/2}];