I have the following code:

f[l_, p_, r_, \[Phi]_] := (r Sqrt[2])^Abs[l] E^(-r^2) LaguerreL[p, Abs[l],2r^2] E^(-I r^2/2) E^(I l \[Phi]);
L[oam1_, r_, \[Phi]_] := f[oam1, 0, r, \[Phi]] {1, I}/Sqrt[2];
R[oam2_, r_, \[Phi]_] := f[oam2, 0, r, \[Phi]] {1, -I}/Sqrt[2];
cl = 1/Sqrt[2];
cr = 1/Sqrt[2];(*1/Sqrt[2]*)
state[oam1_, \[Theta]_, oam2_, r_, \[Phi]_] := cr*R[oam1, r, \[Phi]] + E^(I \[Theta]) cl*L[oam2, r, \[Phi]];
vvpol = VectorPlot[Evaluate@Re[state[7, Pi, -7, Sqrt[x^2 + y^2], ArcTan[x, y]]], {x, -1.4,1.4}, {y, -1.4, 1.4},RegionFunction -> Function[{x, y, z}, 0.2 < x^2 + y^2 < 1.6],
VectorColorFunction -> (Hue[ArcTan[#, #2]/(2 \[Pi])] &), VectorColorFunctionScaling -> False,
Mesh -> None, PlotRange -> All, ImageSize -> 400, Frame -> True, VectorScale -> {0.03, 0.95, None}, VectorStyle -> {{Thickness[0.007], Black}}, VectorPoints -> 25] 

Which produces the following image:

enter image description here

As you can see the Hue map varies circularly, independently on the vector directions. What I want to have is a Hue map that varies depending on the direction of the field.

For instance, all the arrows pointing north will be green and all those pointing south blue and, of course, different color shades from north to south and vice-versa.

Can someone help me?

Thanks in advance :)


1 Answer 1


VectorColorFunction >> Details:

enter image description here

So we can use

VectorColorFunction -> (Quiet @ Hue[ArcTan[#3, #4]/(2 π)] &)

to get

enter image description here

  • $\begingroup$ t is indeed working, thank you! Could you help me to understand it better? I don't think I got the difference between (#,#2) and (#3,#4). What are they precisely doing? $\endgroup$ Commented Aug 28, 2020 at 12:27
  • $\begingroup$ maybe writing the pure function func = Hue[ArcTan[#3, #4]/(2 π)] & as func[x_,y_,vx_,vy_, norm_]:= Hue[ArcTan[vx, vy]/(2 π)] helps? $\endgroup$
    – kglr
    Commented Aug 28, 2020 at 13:13
  • $\begingroup$ Ah ok, got it! So #3 and #4 states we use the values of the field (vx, vy) in the arctan. Perfect! Thank you to make it clearer :) $\endgroup$ Commented Aug 31, 2020 at 7:47

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.