7
votes

I would like to change the view of a 3D plot in matlab such that the y-axis points upward and the z-axis points to left. For example, consider the following plot:

enter image description here

Here the x-axis points forward, the y-axis points to the right and the z-axis points upward.

I would like to have the y-axis points upward and the z-axis points to the left instead. I tried to rotate the plot (using the figure window toolbar rotate button) but I could not get it to work. (It should just be a simple 90 degrees rotation about the x-axis)

Code to generate the plot:

  membrane
  view(100,50)
  xlabel('x-axis');
  ylabel('y-axis');
  zlabel('z-axis');
  grid on
2

2 Answers

11
votes

Try using view. I don't have MATLAB available so I can't test it, but I think it can do what you want.

Example from the documentation:

Set the view along the y-axis, with the x-axis extending horizontally and the z-axis extending vertically in the figure.

view([0 0]);

EDIT:

Try using three inputs to the view function. I can't experiment myself, but you should be able to do it if you choose the right values here.

From documentation:

view([x,y,z]) sets the view direction to the Cartesian coordinates x, y, and z. The magnitude of (x,y,z) is ignored.

EDIT 2:

Check out camroll. I think camroll(90) (possibly in combination with view) will work.

From documentation:

camroll(dtheta) rotates the camera around the camera viewing axis by the amounts specified in dtheta (in degrees). The viewing axis is the line passing through the camera position and the camera target.

4
votes

This was posted a while ago, but in case someone else is looking for ways to set y-axis as the vertical one here is a possible fix.

Manually: In the command window type cameratoolbar('show') which will open an interactive toolbar in your plot from which you could change the view. One of the options is to set a principle axis to x, y, or z.

Or in you script you could use cameratoolbar('SetCoordSys',coordsys) command which sets the principal axis of the camera motion. coordsys can be: x, y, z, or none.

http://uk.mathworks.com/help/matlab/ref/cameratoolbar.html