3
$\begingroup$

The following simple 3D plot always bears a rather wide empty space surrounding the sphere. I only need the sphere and vectors without box or axes. How to remove/control the empty space?

A few padding options I tried do not seem to help. And nonzero PlotRangePadding seems necessary to have a few vectors not cut at the boundary.

m = 1.1;
SliceVectorPlot3D[{y, -x, z}, 
 x^2 + y^2 + z^2 == 1, {x, -m, m}, {y, -m, m}, {z, -m, m}, 
 VectorPoints -> 5, VectorSizes -> 0.9, ViewPoint -> {0.1, -2, 2}, 
 ViewVertical -> {-1, 0., 0.}, Boxed -> False, Axes -> False, 
 PlotRangePadding -> Automatic, ImagePadding -> 0, ImageMargins -> 0, 
 ImageSize -> Medium]

enter image description here

$\endgroup$
0

2 Answers 2

7
$\begingroup$

The default PlotRange setting for SliceVectorPlot3D is {Full, Full, Full} (see the Details and Options section). This means that the full regions of space corresponding to the specified variable ranges will be shown, including any portions in which your function has no plot. The latter will show up as empty space.

To restrict the plot to the minimum calculated range that just includes the function's plot, you want PlotRange -> All instead. Add that option (and perhaps remove all the other padding, margins etc) to minimize white space:

m = 1.1;
SliceVectorPlot3D[
  {y, -x, z}, x^2 + y^2 + z^2 == 1,
  {x, -m, m}, {y, -m, m}, {z, -m, m}, 
  PlotRange -> All,
  Axes -> False, Boxed -> False
  VectorPoints -> 5, VectorSizes -> 0.9
]

minimal size plot


To explain the difference between Full and All in the context of PlotRange, I find these two examples pretty clear:

Plot[Sqrt[x], {x, -3, 3}, PlotRange -> #]& /@ {Full, All}

left: plot with large white space for x<0. Right: plot range has been automatically restricted to x>0

In the plot on the left, the entire $-3<x<3$ range is shown even though nothing can be plotted in the negative $x$ region because the function is complex-valued there. In the plot in the right, the plot range is restricted to only include the values of x for which a plot is generated (i.e. $x\geq 0$.

$\endgroup$
2
  • $\begingroup$ Saved my day. Thank you! $\endgroup$
    – xiaohuamao
    Jun 13, 2022 at 4:39
  • $\begingroup$ @xiaohuamao Glad it helped! Thank you for the accept as well. $\endgroup$
    – MarcoB
    Jun 13, 2022 at 11:51
4
$\begingroup$

Another possibility is to use Method -> {"ShrinkWrap" -> True} (previously featured e.g. here):

With[{m = 1.1},
     SliceVectorPlot3D[{y, -x, z}, x^2 + y^2 + z^2 == 1,
                       {x, -m, m}, {y, -m, m}, {z, -m, m}, 
                       VectorPoints -> 5, VectorSizes -> 0.9, ViewPoint -> {0.1, -2, 2}, 
                       ViewVertical -> {-1, 0., 0.}, Boxed -> False, Axes -> None, 
                       PlotRangePadding -> Automatic, ImageSize -> Medium, 
                       Method -> {"ShrinkWrap" -> True}]]

shrink-wrapped plot

$\endgroup$
1
  • $\begingroup$ Interesting! Never heard of it. $\endgroup$
    – xiaohuamao
    Jun 14, 2022 at 0:45

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.