tags:

views:

71

answers:

2

I know I can after the plot is done, to rotate it with my mouse to the desired angle. Now, I'd like to know how to do the same through code.

+1  A: 

On second look your title involves 3d rotation. For that you can use ViewPoint. The example under the applications tab seems to be what you are looking for.

You can use the ImageRotate function.

ImageRotate@Plot[x, {x, 0, 10}] (*rotate 90 degrees counterclockwise*)
ImageRotate[Plot[x, {x, 0, 10}], phi]  (*rotate phi degrees counterclockwise*)
Davorak
+2  A: 

The 3D view is most conveniently defined through the parameters ViewPoint and ViewVertical (There are additional options: ViewCenter, ViewVector, and ViewAngle, but it usually suffices to leave them on Automatic).

So you can do for example

Plot3D[Cos[x^2 + y^2], {x, -3, 3}, {y, -3, 3}, ViewPoint -> {3, 2, 1}]

To get good values for ViewPoint, etc. I define a function Get3DView as

Get3DView[gfx_] := 
  Options[Unevaluated[gfx], {ViewCenter, ViewVector, ViewVertical, ViewPoint}]

Then you just copy your graphics into Get3DView to get your options:

plotpar = Get3DView[<your graphics pasted here>]

After this you can put your plotpar as options for new plot commands (note the Evaluate):

Plot3D[Cos[x^2 + y^2], {x, -3, 3}, {y, -3, 3}, Evaluate@plotpar]
Janus