I'm trying to make an animation of a time-varying 2D vector field. However, I'm got a difficulty in that Mathematica normalises the length of the vectors with each call to VectorPlot.

A (very simple) example:

myField = {Cos[2 π t], 0};

        VectorPlot[myField /. t -> TT, {x, -1, 1}, {y, -1, 1}],
        {TT, 0, 1}]

Expected result: The arrows grow and shrink in time

The actual result: The arrows remain the same size, but flick direction

Is there some way to fix the length of the arrows relative to the field value?


2 Answers 2


As @Ox4A4D mentioned in the comment, you could use the option VectorScale to set the length of vectors, here is an example code:

myField = {Cos[2 \[Pi] t], 0};
Animate[VectorPlot[myField /. t -> TT, {x, -1, 1}, {y, -1, 1}, 
          VectorScale -> Abs[0.05 Cos[2 Pi TT]]], {TT, 0, 1}]
  • $\begingroup$ Ah, I see -- it's making use of the fact that you know what the maximum value is with this simple function. Perhaps that will put me on the right track... $\endgroup$
    – Gremlin
    Jun 11, 2013 at 15:04

With a slightly more interesting function, and cleaner syntax:

myField[x_, y_, t_] := {Cos[2 Pi x t], Sin[2 Pi y t]};

Animate[VectorPlot[myField[x, y, t], {x, -1, 1}, {y, -1, 1}, 
  VectorScale -> {Small, 1, None}], {t, 0, 1}]

Check the documentation and play around with the arguments to VectorScale as required.


I had indeed misunderstood your requirements. mm.Jang's answer is what you're looking for. 0.05*Norm[myField[t]] should generalize it.

  • $\begingroup$ Your code somehow doesn't work for me... I'm using MMA by the way... $\endgroup$
    – Rod
    Jun 11, 2013 at 13:53
  • $\begingroup$ Any error? I'm on on 64-bit Linux. $\endgroup$ Jun 11, 2013 at 13:59
  • $\begingroup$ @RodLm you must run Clear[myField]; first. $\endgroup$
    – mmjang
    Jun 11, 2013 at 14:00
  • 1
    $\begingroup$ @CoreyKelly Yes, when I run your code nothing happens. I mean, the slider t moves itself but no vector plot is shown. $\endgroup$
    – Rod
    Jun 11, 2013 at 14:00
  • 2
    $\begingroup$ @mm.Jang Thank you... problem solved! Corey, please forget what I've written before. $\endgroup$
    – Rod
    Jun 11, 2013 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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