I was plotting a VectorPlot
and restricting it to the physically meaningful region using RegionFunction
. To my surprise, the result for the following code was an empty plot.
tempa = 0.2;
vectorfield = {(0.02*x y)/(x^2 + y^2)^(5/2),
1/(x^2 + y^2) (x^2 (1 - 0.008/(x^2 + y^2)^(3/2)) + y^2 (1 + 0.016/(x^2 + y^2)^(3/2)))}
VectorPlot[vectorfield, {x, -1, 1}, {y, -1, 1},
RegionFunction -> ((tempa^2 < (#1^2 + #2^2 ) < 1 && #2 < 0) &),
VectorColorFunction -> "Rainbow"]
Investigating the problem further by removing the RegionFunction
, I realized that the probem was with the vector's value at the origin, which is very large. In fact, the following code with the RegionFunction option removed returns the following image.
VectorPlot[vectorfield, {x, -1, 1}, {y, -1, 1},
VectorColorFunction -> "Rainbow"]
By adding the options of VectorPoints
and VectorScale
, I was able to display some meaningful information, as shown below.
VectorPlot[vectorfield, {x, -1, 1}, {y, -1, 1},
VectorPoints -> {20, 20}, VectorScale -> 0.5,
RegionFunction -> ((tempa^2 < (#1^2 + #2^2 ) < 1 && #2 < 0) &),
VectorColorFunction -> "Rainbow"]
Alternatively, using VectorScale
as follows
VectorPlot[vectorfield, {x, -1, 1}, {y, -1, 1},
VectorPoints -> {20, 20}, VectorScale -> {Automatic, Automatic, If[#5 > 3, 0, #5] &},
RegionFunction -> ((tempa^2 < (#1^2 + #2^2 ) < 1 && #2 < 0) &),
VectorColorFunction -> "Rainbow"]
seems to be a better way to scale the length of the vectors, but it still doesn't help with the ColorFunction
.
I would expect Mathematica to scale the colors of the vectors based on the range of norms in the
RegionFunction
. Is this not the case, or is there something wrong with my code?
VectorScale -> {Automatic, Automatic, If[#5 > 3, 0, #5] &}
as an option seems to help with the scaling for the initial length of the vectors but doesn't help with the color function - perhaps I'm doing something wrong about the color. $\endgroup$VectorPoints
? $\endgroup${30, 30}
while keepingVectorScale
at 0.5, then the points get smaller and smaller for constant image size. It doesn't seem to help with the colour, either. $\endgroup$VectorColorFunction
to color according to some other criterion. $\endgroup$VectorPlot3D[verysmallnumber*{x, y, z}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, VectorColorFunction -> "Rainbow"]
gives the same image no matter what value you choose forverysmallnumber
as the values are normalized. $\endgroup$