4
$\begingroup$

Working on a vector field, I'd like to use a ColorFunction dependent on both the vector direction and its norm. According to the documentation of ListVectorDensityPlot, one has access to ColorFunction -> Function[{x, y, vx, vy, s},.... However, in the codes below with two equivalent plottings, errors occur as if one can not use vx,vy. Same for both data0 and data1.

On the other hand, it does work when we delete the s entry in data0 or data1. However, I need explicit s for another reason: without explicit s, it will automatically plot a little beyond the supplied data range, which may cause trouble in certain cases.

Is there a way to access vx,vy?

f = {-y, x};
s = Norm[f];
data0 = Table[{f, s}, {x, -3, 3, 0.2}, {y, -3, 3, 0.2}];
data1 = Table[{{x, y}, {f, s}}, {x, -3, 3, 0.2}, {y, -3, 3, 0.2}];

ListVectorDensityPlot[data1, PlotRange -> Full, 
 PlotRangeClipping -> False, VectorColorFunction -> None, 
 VectorRange -> All, VectorStyle -> Black, 
 ColorFunctionScaling -> {False, False, False, False, True}, 
 ColorFunction -> 
  Function[{x, y, vx, vy, s}, Hue[ArcTan[vx, vy]/(2 \[Pi]), s]]]

ListVectorDensityPlot[data1, PlotRange -> Full, 
 PlotRangeClipping -> False, VectorColorFunction -> None, 
 VectorRange -> All, VectorStyle -> Black, 
 ColorFunctionScaling -> {False, False, False, False, True}, 
 ColorFunction -> (Hue[ArcTan[#3, #4]/(2 \[Pi]), #5] &)]
$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.