4
$\begingroup$

One can use the function VectorColorFunction in VectorPlot3D to color vectors according to their norms. How to color vectors according to the angle they are pointing along, say, in the x-y plane? Thanks!

$\endgroup$
6
$\begingroup$
VectorPlot3D[{x, y, z}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
 VectorColorFunction -> (Hue@Rescale[Arg[#4 + I #5], {0, 2 Pi}] &), 
 VectorColorFunctionScaling -> False] 

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Arg[]'s range is $(-\pi,\pi]$. ;) $\endgroup$ – J. M.'s ennui Nov 5 '15 at 15:17
  • $\begingroup$ @J.M. And the Plots are quite different, I see :) $\endgroup$ – Dr. belisarius Nov 5 '15 at 15:25
7
$\begingroup$

There are a lot of arguments in VectorColorFunction. In your particular case you can write the following

VectorPlot3D[{x, y, z}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
 VectorColorFunction -> 
  Function[{x, y, z, vx, vy, vz, v}, Hue[ArcTan[vx, vy]/2/π]], 
 VectorColorFunctionScaling -> False]

enter image description here

$\endgroup$
2
  • $\begingroup$ I was a bit slow... However, I believe this explicit function is more clear for OP. $\endgroup$ – ybeltukov Nov 5 '15 at 15:25
  • $\begingroup$ Thanks a lot, ybeltukov, I will upvote your answer! Much appreciated. $\endgroup$ – jarm Nov 6 '15 at 7:16

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.