Plotting a 3D surface on the XZ plane

I've got some 3D surface data I want to visualise, which I've been using the surf(X,Y,Z) function for. This creates a 'horizontal' surface in the XY plane. However, some of the 3D data I am visualising describes a 'vertical' surface (like a wall), and so I would like to plot it in the XZ plane, with the y values being depth.
I have tried plotting the data as a 'horizontal' XYZ surface and rotating the view - but because of how 'surf' works this will only provide a 2D view with no depth element (Matlab will only provide a 3D view from 'above'). You can of course create a surface by swapping the depth and height axes (i.e. plot surf(X,Z,Y)), but this still only creates a surface in the XY plane with Z depth values. I want to create a surface in the XZ plane, with Y values. Any ideas?

Answers (1)

I’m not certain what you’ve already done. I would use the rotate (link) function. You might have to re-label your axes later, but that is relatively straightforward.

4 Comments

Thanks for your suggestion! Rotate does rotate my 3D shape, but as you say it messes with my axes. It also doesn't rotate the colour scale which indicates depth (you can observe this on the examples in the linked page you provided), so that rotating by 90 degrees (to get my vertical surface) means the lowest rows of data are all blue, and the highest rows are all yellow. I suspect there are ways around this, but I was hoping there was a short (lazy!) solution which would rotate the surface and colour scale (and axes).
I didn’t notice that originally.
When I ran the demo code and specified the axis to scale the colours by, the colours remained in the rotated figure.
Example:
[X,Y,Z] = peaks(25);
C = Z;
figure(1)
subplot(1,2,1)
surf(X,Y,Z)
axis tight
subplot(1,2,2)
hSurface = surf(X,Y,Z,C);
direction = [1 0 0];
rotate(hSurface,direction,90)
axis tight
Experiment with that with your data.
My pleasure.
A vote would be appreciated!

Sign in to comment.

Asked:

on 20 Jan 2017

Commented:

on 5 Jul 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!