2
$\begingroup$

I'm trying to configure 3D plot to be displayed as a perfect cube.

Setting AspectRatio -> 1 like you would do in a reqular Plot to make image rectangular does not seem to work for 3D case:

Plot3D[{1/(x^2 + y^2)}, {x, 0, 4}, {y, 0, 4}, 
  PlotRange -> {{0, 4}, {0, 4}, {0, 8}}, AspectRatio -> 1, 
  Mesh -> None, PlotStyle -> {{LightBlue, Opacity[0.5]}}, 
  Lighting -> {{"Ambient", LightBlue}}, ClippingStyle -> None, 
  BoundaryStyle -> {Blue}, PlotPoints -> 100, 
  AxesLabel -> {"x", "y", "z"}
]

Which setting should I use and how?

enter image description here

$\endgroup$
1
  • 4
    $\begingroup$ You are probably looking for BoxRatios. Try removing your AspectRatio option, and replacing it with BoxRatios -> Automatic, which should adjust the shape of the graphics box to correspond to the actual coordinate values. $\endgroup$
    – MarcoB
    Feb 12, 2017 at 4:13

1 Answer 1

9
$\begingroup$

Replace AspectRatio with BoxRatios

p1 = Plot3D[{1/(x^2 + y^2)}, {x, 0, 4}, {y, 0, 4}, 
   PlotRange -> {{0, 4}, {0, 4}, {0, 8}}, BoxRatios -> {1, 1, 1}, 
   Mesh -> None, PlotStyle -> {{LightBlue, Opacity[0.5]}}, 
   Lighting -> {{"Ambient", LightBlue}}, ClippingStyle -> None, 
   BoundaryStyle -> {Blue}, PlotPoints -> 100, 
   AxesLabel -> {"x", "y", "z"}];
p2 = Plot3D[{1/(x^2 + y^2)}, {x, 0, 4}, {y, 0, 4}, 
   PlotRange -> {{0, 4}, {0, 4}, {0, 8}}, BoxRatios -> Automatic, 
   Mesh -> None, PlotStyle -> {{LightBlue, Opacity[0.5]}}, 
   Lighting -> {{"Ambient", LightBlue}}, ClippingStyle -> None, 
   BoundaryStyle -> {Blue}, PlotPoints -> 100, 
   AxesLabel -> {"x", "y", "z"}];
GraphicsRow[{p1, p2}, ImageSize -> {800, Automatic}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Young, at first I though that BoxRatios -> {1, 1, 1} was not what the OP wanted (I thought they wanted the length of each axis to be proportional to the range of the variables represented), but on second reading of their question, you might be right! I wonder, would you consider perhaps including the output with BoxRatios -> Automatic as well, so both options are presented? $\endgroup$
    – MarcoB
    Feb 12, 2017 at 4:43
  • $\begingroup$ @MarcoB Sure. Good idea. $\endgroup$
    – Young
    Feb 12, 2017 at 4:53

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