5
$\begingroup$

While trying to arrange a grid of 3d-plots using Plot3D and GraphicsGrid (or simply Grid) I noticed that each individual plot is getting resized and a lot of whitespace is being added between the plot body and plot label. Is there a way to display the 3d-plots next to each other with the label distance remaining the same as it was outside of Grid?

I tried to illustrate this with an example below using Row though it applies to other commands such as GraphicsGrid as well.

Here is my code:

{ p1 , p2 } = Plot3D[  # , {x , -5 , 5 } , { y, -5 , 5 } , 
ViewPoint -> {1, 1, .1 }, 
PlotLabel -> #, ImageSize -> Small ] & /@ { x y , x y^2};
Row@{p1,p2}

Each of the plots individually has the label touching the plot body enter image description here

But when they are together inside a Row or Grid each plot is apparently resized to a square bounding box (orange) and the label is too far away enter image description here

$\endgroup$
0

1 Answer 1

3
$\begingroup$

Use Labeled to place the labels and use the option PlotRegion in Plot3D:

pr22 = 1.4;

{lp1, lp2} = Labeled[Plot3D[#, {x, -5, 5}, {y, -5, 5}, ViewPoint -> {1, 1, .1}, 
      SphericalRegion -> True, ImageSize -> Small, 
      PlotRegion -> {{0, 1}, {0, pr22}}], #, Top] & /@ {x y, x y^2};

Row @ {lp1, lp2}

enter image description here

$Version
"11.3.0 for Microsoft Windows (64-bit) (March 7, 2018)"

In version 13.0.0 (Wolfram Cloud) you can simply use Labeled:

{lpa, lpb} = Labeled[Plot3D[#, {x, -5, 5}, {y, -5, 5}, 
   ViewPoint -> {1, 1, .1}, ImageSize -> Small ], #, Top] & /@ {x y, x y^2};

Row @ {lpa, lpb} 

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks a lot, this worked! Curiously, on my machine (13.0.0 for Linux x86 (64-bit)) the Labeled version does not work without PlotRegion. Also, SphericalRegion seems to be unnecessary. I wonder if there is a way to figure out in advance what the value of PlotRegion should be? $\endgroup$
    – And R
    Mar 3, 2022 at 8:50
  • $\begingroup$ @AndR, I don't know of any automatic way to set PlotRegion. For 3D graphics we will need different settings PlotRegion for different viewpoints to get the desired result. $\endgroup$
    – kglr
    Mar 3, 2022 at 9:11

Your Answer

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

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