0
$\begingroup$

I am trying to plot a 3D vector field with VectorPlot3D but I want it only evaluated across the $xy$-plane. I.e. I want the vectors in 3-space pointing out of the $xy$-plane, but I only want one "layer" of them vertically (where $z = 0$). But when I specify VectorPoints -> {8, 8, 1} as an option to VectorPlot3D it throws an error Value of option PlotPoints -> {8,8,1} is not an integer >= 2.

Here is an example of what I am trying to achieve:

enter image description here

I hacked this together by ploting it with a large $z$ range and PlotPoints -> {8,8,3}, then photoshopping out the top and bottom layers of vectors. But this is really klunky and annoying as I have several of these to do.

This minimum bound of 2 for the evaluation point resolution seems pretty arbitrary and weird, not to mention really annoying for my purposes. Is there any way I can achieve what I am attempting to?

$\endgroup$
  • 1
    $\begingroup$ Duplicate? mathematica.stackexchange.com/questions/8984/… $\endgroup$ – Simon Rochester Dec 14 '16 at 5:54
  • $\begingroup$ @SimonRochester Almost, it seems the OP there only wants one arrow total, I want multiple vectors but only one in the $z$-direction. I'll try to apply some of those here though. It baffles me that this may be impossible since this seems it should be a pretty simple task. $\endgroup$ – PGmath Dec 14 '16 at 6:29
  • $\begingroup$ Specifying an explicit list of VectorPoints seems to work. You could also try using PlotRange to trim out the unwanted vectors in the z direction. $\endgroup$ – Simon Rochester Dec 14 '16 at 8:23
  • 2
    $\begingroup$ Please post code so that we can reproduce the issue. $\endgroup$ – C. E. Dec 14 '16 at 9:12
  • $\begingroup$ @C.E. Just put VectorPoints -> {8, 8, 1} as an option to VectorPlot3D, and it will complain the value isn't >= 2. $\endgroup$ – PGmath Dec 14 '16 at 14:53
3
$\begingroup$

VectorPoints has an alternate syntax that lets you specify an explicit list of coordinates where you want the vectors placed. VectorPlot3D doesn't complain if they're all in the same plane, as long as there are at least two points in total:

VectorPlot3D[{0, 0, Sin[Pi x]}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
  VectorPoints -> Flatten[Table[{x, y, 0}, {x, -1, 1, .25}, {y, -1, 1, .25}], 1], 
  PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}
]

Mathematica graphics

You could also plot more vectors than you want in the z direction and then trim them out using PlotRange:

VectorPlot3D[{0, 0, Sin[Pi x]}, {x, -1, 1}, {y, -1, 1}, {z, -2, 2},
  VectorPoints -> {8, 8, 3}, VectorScale -> .1, 
  PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}
]

Mathematica graphics

Or you could delete the unwanted arrows entirely from the graphics object:

DeleteCases[
  VectorPlot3D[{0, 0, Sin[Pi x]}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1},
    VectorPoints -> {8, 8, 3}, VectorScale -> .1, 
    PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}
  ], 
  Arrow[{{_, _, z1_}, {_, _, z2_}}] /; Mean[{z1, z2}] != 0, 
  Infinity
]

Mathematica graphics

Or you could set the vector field to zero for z != 0:

VectorPlot3D[
  If[Abs[z] < .01, {0, 0, Sin[Pi x]}, {0, 0, 0}], {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
  VectorPoints -> {8, 8, 3}, VectorScale -> .1, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}
]

Mathematica graphics

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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