3
$\begingroup$

Mathematica uses in my opinion a weird concept of camera alignment. I would like to align the axes in Mathematica in the same way how Matlab does.

For example, in the following picture you see a Matlab-3D-Plot where the z-axis is vertically.

Matlab

Sure, I could use ViewVertical->{0,0,0} in Mathematica to get the same result, but only for the left line of the box. And also the graph is skewed.

Mathematica

I'm looking for a code to align the camera by an azimuth and altitude angle which preserves a vertical z-axis and a vertical graph. In addition and if possible, the ViewPoint should be more or less the default ViewPoint->{1.3,-2.4,2}.

Here you can see the solution of @MarcoB. High ViewPoint

$\endgroup$

1 Answer 1

5
$\begingroup$

The "Details" section of the documentation for ViewPoint states that you can use high values for this option to reduce the distortion due to perspective, which is the effect that bothers you.

However, this is the equivalent of looking at your plot from really far away, so you should then drastically reduce the value of ViewAngle (i.e. the "zoom") to include a much smaller angle than usual, possibly a fraction of a degree, so that your plot is shown at reasonable dimensions.

You may also want to set the BoxRatios option to make your plot look more "square".

In short, take a look at the result below, then tinker with the values of distances in ViewPoint and angles in ViewAngle to obtain the result most pleasing to you.

Plot3D[Exp[-(x^2 + y^2)], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, BoxRatios -> {1, 1, 1}, ColorFunction -> "Rainbow", ViewPoint -> {-150, -160, 50}, ViewAngle -> .5 Degree ] 

Mathematica graphics

As you settle on values that work for you, you may consider setting those options once for all your Plot3D functions using SetOptions:

SetOptions[Plot3D, ViewPoint -> {-150, -160, 50}, ViewAngle -> .5 Degree ] 

This will influence all the Plot3D expressions you evaluate afterwards in that session.


@GuessWhoItIs pointed out the OP's preference for the built-in ViewPoint position. That can be retained, although I feel that it may result in less "Matlab-like" results. Anyway, one can gauge what multiple of the standard ViewPoint, i.e. how far ViewPoint has to be set, to get rid of perspective-induced distortion with the following series of plots.

In these plots I am trying to obtain results close to what would be obtained with the default options and ViewAngle set at $35\deg$, i.e. the built-in value.

{Style[#, FontSize -> 32, FontFamily -> "Arial Black"], Plot3D[Exp[-(x^2 + y^2)], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, BoxRatios -> {1, 1, .8}, ColorFunction -> "Rainbow", ViewPoint -> # {1.3, -2.4, 2}, ViewAngle -> 30/# Degree, ImageSize -> Medium]} & /@ {1, 2, 5, 10, 20, 50, 75, 100, 200}; Grid@ArrayReshape[%, {3, 3, 2}] 

Mathematica graphics

$\endgroup$
3
  • 1
    $\begingroup$ As OP wanted a ViewPoint as close to the default as possible, a setting that is a modestly sized multiple of {1.3, -2.4, 2.} might be appropriate. $\endgroup$ Commented May 26, 2015 at 0:52
  • $\begingroup$ @Guesswhoitis. It is true that I was going a bit overboard with the multiplier to ViewPoint. I've added a few more smaller sample values for comparison. On the other hand, though, I feel that the standard ViewPoint does not seem to be what Matlab uses, and I thought that the OP would value closeness to their desired figure over sticking to an arbitrary choice of ViewPoint. Anyway, OP should be able to take their pick now :-) $\endgroup$ Commented May 26, 2015 at 1:13
  • $\begingroup$ @MarcoB ViewAngle->All is better than the own scaling, because the bounding box fills the viewing area. $\endgroup$ Commented May 26, 2015 at 9:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.