I am surprised at the behavior of VectorPlot in the following sense: plotting a vector field and examining the output at a point $(x_0,y_0)$ reveals that Mathematica doesn't draw the tail of the arrow at $(x_0,y_0)$ but rather it draws the base of the arrowhead at $(x_0,y_0)$. (Of course, the output points the arrow in the correct direction.)

This is, in my opinion, confusing/misleading for students learning about vector fields.

Has anyone developed an efficient workaround to this, so that when we plot the vector field we get output that positions the tail of the arrowhead at the point $(x_0,y_0)$ rather than the base of the arrowhead?

Here is some output which perhaps more clearly portrays the issue:

pts = Flatten[Table[{i, j}, {i, -1, 1, .5}, {j, -1, 1, .5}], 1];
p1 = ListPlot[pts, PlotStyle -> {{Red, PointSize[Large]}}];
p2 = VectorPlot[{x + y, 1}, {x, -1, 1}, {y, -1, 1}, VectorPoints -> pts, VectorScale -> Medium];
Show[p2, p1]

enter image description here


The arrow is actually centred over the spot, so we simply need to shift the arrow by half its length:

Show[p2 /. Arrow[{p_, q_}] :> Arrow[{p + (q - p)/2, q + (q - p)/2}], p1]

enter image description here

| improve this answer | |
  • $\begingroup$ Thanks, this accomplishes what I desire. It seems to me that this should be the default behavior of VectorPlot. $\endgroup$ – JohnD Jul 17 '12 at 20:54
  • $\begingroup$ Have another Enlightened badge, Simon. :-) $\endgroup$ – Mr.Wizard Jul 17 '12 at 23:36
  • $\begingroup$ @Mr.Wizard, thank you. It's my first one actually :-) $\endgroup$ – Simon Woods Jul 18 '12 at 21:13
  • 4
    $\begingroup$ @texasAUtiger: Your reaction to the default behavior was mine as well. But on my part this is due primarily because math textbooks and teachers draw the fields with the tails at the specified points; hence the dissonance for students who look at the Mathematica result. But in truth the Mathematica default may be more reasonable: having the middle of the arrow at the point gives a more realistic representation of the flow through the point, rather than the flow away from the point. $\endgroup$ – murray Jul 19 '12 at 0:21
  • 1
    $\begingroup$ @texasAUtiger, something like myVectorPlot[x__]:=VectorPlot[x]/.Arrow[{p_,q_}]:>Arrow[{p+(q-p)/2,q+(q-p)/2}];SetAttributes[myVectorPlot,HoldAll] $\endgroup$ – Simon Woods Jul 19 '12 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.