How do I draw contour on the other two planes when using SURFC?

9 views (last 30 days)
I use SURFC to plot my data(eg. peaks(30)) and the contour on xy plane looks great for knowing the maximum and minimum at some levels. But I also want to have contours on yz plane and zx plane. Is it possible to do that?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 9 Apr 2013
The CONTOURSLICE may be an easy way to achieve this when you have the volume data for your surface plot. But if there's no volume data, it'll get more complex to do that. You'll do CONTOUR for each plane by changing the order of the input arguments and then swapping corresponding x/y/zdata of each contour line to achieve the effect. Please refer to the following example.
[X,Y,Z] = peaks(30);
h1=surfc(X,Y,Z);
xmin=-3;xmax=3;ymin=-3;ymax=3;zmin=-10;zmax=10;
axis([xmin xmax ymin ymax zmin zmax])
hold on;
%%contour on yz plane
[C,h]=contour(Y,Z,X);
hpatch = get(h,'Children');
for i = 1:length(hpatch)
ch = hpatch(i);
xdata = get(ch,'Xdata'); %
ydata = get(ch,'Ydata');
set(ch,'Xdata',zeros(size(xdata))+xmax);
set(ch,'Zdata',ydata);
set(ch,'Ydata',xdata);
end
%%contour on xz plane
[C,h]=contour(X,Z,Y);
hpatch = get(h,'Children');
for i = 1:length(hpatch)
ch = hpatch(i);
xdata = get(ch,'Xdata'); %
ydata = get(ch,'Ydata');
set(ch,'Ydata',zeros(size(ydata))+ymax);
set(ch,'Zdata',ydata);
set(ch,'Xdata',xdata);
end
For scatter data, you could also refer to related solution below "Is it possible to draw contour on YZ and ZX planes?".
  1 Comment
Walter Roberson
Walter Roberson on 13 May 2020
Note: the above is valid only for HG1 -- that is, up to and including R2014a.
The instructions do not apply for R2014b and later, which draws contours differently.

Sign in to comment.

More Answers (0)

Categories

Find more on Author Block Masks in Help Center and File Exchange

Products


Release

R2012b

Community Treasure Hunt

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

Start Hunting!