The following graph shows the vector plot. How can I plot the solid lines which represents how the vectors are spatially varying and both on the same graph (vector plot and stream field)?

Evaluate[Grad[{z - Sin[2 \[Pi] y] Cos[\[Pi] x]}, {x, y, 
 z}]], {"XStackedPlanes", 2}, {x, -1/2, 1/2}, {y, 0, 2}, {z, 0, 1}]

1 Answer 1


Here are the streamlines using the centers of the arrows in the vector plot as initial conditions:

svp = SliceVectorPlot3D[
  Evaluate[Grad[{z - Sin[2 π y] Cos[π x]}, {x, y, z}]],
    {"XStackedPlanes", 2}, {x, -1/2, 1/2}, {y, 0, 2}, {z, 0, 1}]

streamline[point_] :=
    NDSolveValue[{{x'[t], y'[t], z'[t]} == 
       First@(Grad[{z - Sin[2 π y] Cos[π x]}, {x, y, z}] /. 
          v : x | y | z :> v[t]), {x[0], y[0], z[0]} == point,
      WhenEvent[Abs[x[t]] > 1/2, "StopIntegration"],
      WhenEvent[Abs[y[t] - 1] > 1, "StopIntegration"],
      WhenEvent[Abs[z[t] - 1/2] > 1/2, "StopIntegration"]},
     Through[{x, y, z}["ValuesOnGrid"]], {t, -10, 10}];

points = Cases[svp, Arrow[a_] :> Mean[a], Infinity];

 Graphics3D[{Red, streamline /@ points}]

There's no StreamPlot for 3D, so manual construction is needed. You can use Arrow instead of Line in the definition of streamline. You can also use Arrowheads to put multiple arrows on them.

  • $\begingroup$ Error occurred during execution in v14. $\endgroup$
    – lotus2019
    Mar 15 at 1:25

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.