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]] &)

enter image description here

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.

enter image description here

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?

  • 2
    $\begingroup$ In 9.0 it works, in 10.0 it's the same thing you describe. $\endgroup$
    – Szabolcs
    May 20, 2016 at 22:01
  • $\begingroup$ 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.) $\endgroup$
    – Rashid
    May 21, 2016 at 12:55
  • $\begingroup$ 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.) $\endgroup$
    – Rashid
    May 21, 2016 at 13:07
  • $\begingroup$ @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.) $\endgroup$
    – bbgodfrey
    May 23, 2016 at 2:24

1 Answer 1


The bug described above is largely resolved in

(* "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.


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

enter image description here

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]

enter image description here

So, at least part of the bug persists.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.