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!
2 Answers
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]
-
$\begingroup$
Arg[]
's range is $(-\pi,\pi]$. ;) $\endgroup$ Nov 5, 2015 at 15:17 -
$\begingroup$ @J.M. And the Plots are quite different, I see :) $\endgroup$ Nov 5, 2015 at 15:25
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]
-
$\begingroup$ I was a bit slow... However, I believe this explicit function is more clear for OP. $\endgroup$ Nov 5, 2015 at 15:25
-
$\begingroup$ Thanks a lot, ybeltukov, I will upvote your answer! Much appreciated. $\endgroup$– jarmNov 6, 2015 at 7:16