James
James

Reputation: 753

Place MATLAB contour plot on any plane

I have a 3d plot and I'd like to put a 2d contour plot in a vertical (XZ) plane. When I place a contour plot, it always places it on a XY plane. If it were a pcolor, I could swap the YData and ZData using a set and a get, which works fine. Only I want the contour plot, not a pcolor.

Thanks, James

Upvotes: 1

Views: 1327

Answers (1)

David
David

Reputation: 8459

Since you only have 2D data, just extrapolate it out to make it 3D, by repeating it in the Y direction (in this case).

% Sample data
m=-1:1:1;
[X,Y]=meshgrid(m)
Z=X+Y

% Create the 3D position grids
[xx,yy,zz]=meshgrid(m)
% Copy the data the appropriate number of times
vv=repmat(Z,[1 1 length(m)])
% permute dimensions so that everything is constant in the second (Y) dimension
vv=permute(vv,[1 3 2])

contourslice(xx,yy,zz,vv,[],[0 0],[])
view([30 20])

Upvotes: 1

Related Questions