# Animation of VectorPlot

I am stuck with creating animation of vector plot. My example code is simple

myField[x_, y_, t_] := {0, 100*Sin[2*Pi*50*t]*Cos[Pi*y]};
Animate[VectorPlot[myField[x, y, t], {x, 0, 1}, {y, -0.5, 0.5},
VectorColorFunction -> "Rainbow", PlotLegends -> Automatic], {t, 0, 2/50}]


It is working nicely, except that vectors are rescaled every timestep. Result can be seen in gif animation. I found this discussion, and came up with code

With[{vectorscale = {0, 100}, time = 0.08},
Legended[VectorPlot[myField[x, y, time], {x, 0, 1}, {y, -0.5, 0.5},
VectorColorFunction ->
Function[{x, y, vx, vy, n},
ColorData[{"ThermometerColors", vectorscale}][Abs[myField]]],
VectorScale -> {0.03, Automatic, None},
VectorColorFunctionScaling -> False, VectorPoints -> 25,
AspectRatio -> 1],
BarLegend[{ColorData[{"ThermometerColors", vectorscale}],
vectorscale}]]]


As you see, this one is not animation, but attempt to create fixed time plot with controllable color scaling. Unfortunately I am missing something very basic, because it does not work at all, I cannot even understand this result: Can someone point out what am I missing?

Thank You!

changes:

• Dynamic on VectorPlot to not recreate Legend at each step

• VectorColorFunction should be applied to the 5th argument n which is a norm of your field, not to the field function. You can square it if you need Abs though.

With[{vectorscale = {0, 100}},
Animate[Legended[
Dynamic@VectorPlot[myField[x, y, time], {x, 0, 1}, {y, -0.5, 0.5},
VectorColorFunction ->
Function[{x, y, vx, vy, n},
ColorData[{"ThermometerColors", vectorscale}][n]],
VectorScale -> {0.05, Automatic, None},
VectorColorFunctionScaling -> False, VectorPoints -> 15,
AspectRatio -> 1],
BarLegend[{ColorData[{"ThermometerColors", vectorscale}],
vectorscale}]], {time, 0, 2/50}]] • Thank you! Exactly what I needed – vargss Mar 3 '17 at 12:50
• @vargss glad I could help, please take a tour – Kuba Mar 4 '17 at 19:14