Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 16 down vote accepted

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

share|improve this answer
    
Thanks, this accomplishes what I desire. It seems to me that this should be the default behavior of VectorPlot. –  JohnD Jul 17 '12 at 20:54
    
Have another Enlightened badge, Simon. :-) –  Mr.Wizard Jul 17 '12 at 23:36
    
@Mr.Wizard, thank you. It's my first one actually :-) –  Simon Woods Jul 18 '12 at 21:13
1  
@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. –  murray Jul 19 '12 at 0:21
1  
@texasAUtiger, something like myVectorPlot[x__]:=VectorPlot[x]/.Arrow[{p_,q_}]:>Arrow[{p+(q-p)/2,q+(q-p)/2}];S‌​etAttributes[myVectorPlot,HoldAll] –  Simon Woods Jul 19 '12 at 17:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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