# Cannot reproduce VectorDensityPlot solution from question 37459

Bug introduced in 10.0 or earlier and persisting through 11.0; largely but not entirely resolved in 11.1, with residual problems persisting through 11.3.

(Reported to Wolfram Technical Support on 24 May 16)

Using Mathematica 10.4.1 for Microsoft Windows (64-bit) (April 11, 2016), I cannot reproduce Kuba's Nov 20 '13 answer to question 37459.

f1[x_, y_] := {x^2 + y^2, y^2}
f2[x_, y_] := {2 x y, 2 x y - x^2}
h[x_, y_] := x - y

f[x_, y_] := Piecewise[{{f1[x, y], h[x, y] >= 0}, {f2[x, y], h[x, y] < 0}}]

VectorDensityPlot[f[x, y], {x, -5, 5}, {y, -5, 5}, VectorStyle -> Directive[Red],
VectorScale -> Large, ColorFunctionScaling -> True,
ColorFunction -> (GrayLevel[Sign@h[#, #2]] &)
] Most obviously, the vectors here are the wrong color. A number of other undesirable differences also are apparent. Stranger yet, evaluating this short notebook a second time produces a different, blatantly incorrect plot. The VectorDensityPlot options used are not at fault, because the simpler

VectorDensityPlot[f[x, y], {x, -5, 5}, {y, -5, 5}, VectorStyle -> Red]


behaves similarly. Suggestions?

• In 9.0 it works, in 10.0 it's the same thing you describe. May 20, 2016 at 22:01
• Interestingly, after evaluating this plot, all the examples for the VectorStyle in the VectorDensityPlot documentation also display incorrectly. (But they are fine if I quit the kernel and do them first.) May 21, 2016 at 12:55
• The instability in VectorDensityPlot (that subsequently evaluated plots look wrong) seems to be related to the function within function calls (f[x,y] depending on f1[x,y],f2[x,y], andh[x,y]). For example, if I directly define f[x_, y_] := Piecewise[{{{x^2 + y^2, y^2}, x - y >= 0}, {{2 x y, 2 x y - x^2}, x - y < 0}}], the plot looks like the first example here, but then stays the same with subsequent evaluations. (I am using 10.4.0 on a Windows 64-bit system.) May 21, 2016 at 13:07
• @Rashid I get the same behavior with your code that I did with Kuba's. (I am using 10.4.1 on a Windows 64-bit system.) May 23, 2016 at 2:24

The bug described above is largely resolved in

\$Version
(* "11.1.0 for Microsoft Windows (64-bit) (March 13, 2017)" *)


Executing the notebook the first time yields the first plot in the question, but running it subsequent times again yields the first plot, not the second. The result still is not the same as that of Kuba (different color, slightly different range of ticks, less desirable placement of vectors), but the main problem now appears resolved.

However,

VectorDensityPlot[f[x, y], {x, -5, 5}, {y, -5, 5}, VectorStyle -> Red] does not display Red vectors, even though a similar plot, adapted from the VectorDensityPlot documentation, does:

VectorDensityPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -5, 5}, {y, -5, 5}, VectorStyle -> Red] So, at least part of the bug persists.