wolfram-mathematica2d-vector

How to assign the VectorColorFunction to phase (instead of magnitude) in VectorPlot


I would like to plot 2D vector by assigning the color to the phase/angle of the data points (instead of their magnitude), like that color used in ComplexPlot function. However, ComplexPlot dose not have the VectorMarker I like to use and show the magnitude of the datapoints.

This is what I got with

VectorPlot[{x, y}, {x, -3, 3}, {y, -3, 3}, VectorMarkers -> "CircleArrow", VectorColorFunction -> Hue]

enter image description here

I also tried to assigne VectorColorFunction -> ArcTan[y/x] but this does not work.

==========Amendment after suggestions of @mikuszefski ==============

I modified the code to VectorPlot[{x, y}, {x, -3, 3}, {y, -3, 3}, VectorMarkers -> "CircleArrow", VectorColorFunction -> (ColorData["Hue"][Arg[#3 + I #4]] &)]

However, an error message shows "ColorData::notent: Hue is not a known entity, class, or tag for ColorData. Use ColorData[] for a list of entities."

I found an available color map "Rainbow"

VectorPlot[{x, y}, {x, -3, 3}, {y, -3, 3}, VectorMarkers -> "CircleArrow", VectorColorFunction -> (ColorData["Rainbow"][Arg[#3 + I #4]] &)] Here is the result:

enter image description here

But "Rainbow" is not cyclic color table suitable for display angles. Anyway, it now allowed map the color according to angles (a defined function). The next step is to generate a real Hue color table which can be passed to ColorData, I guess.


Solution

  • Looking at the Docs of VectorColorFunction you probably need something like that

    VectorColorFunction -> (ColorData["Rainbow", (Pi + Arg[#3 + I #4])/ (2 Pi) ]&)
    

    The VectorPlot automatically passes 5 arguments, which should be x,y, vx, vy and r i.e. the norm. so you can easily get the angle creating a complex number out of the vector components, i.e. argument 3 and 4. Hence, you have to provide the according pure function. In contrast to the example in the docs, here I rescale manually.

    Info... I do not have Mathematica at hand right now, so I could not test the answer.

    Update

    It seems that Hue is not valid with ColorData, so I changed the above code to Rainbow. Looking at the ColorFunction docs to get Hue it should probably read

    VectorColorFunction -> Function[ { x, y, v, w, r }, Hue[ (Pi + Arg[ v + I w ]) / (2 Pi) ] ]
    

    which should be equivalent to

    VectorColorFunction -> ( Hue[ (Pi + Arg[ #3 + I #4 ] ) / (2 Pi) ]& )