contour lines obscured on a surface.

I'm plotting a surface - this seems to work fine. I get the colours I expect and the shading looks ok.
I've added contours to show isolines. Except as you can see in the image some of the text is obscured by the shading seemingly. It makes the contour lines hard to read and overall makes the plot look a bit rubbish!
Code below, variable names changed to obscure IP:
levels = [0:1:15]
figure(1);
colormap(jet)
str=sprintf('My title');
title(str);
hold on;
grid on;
surf(X,Y,Z)
shading interp
[C,h] = contour3(X,Y,Z,'k','LineWidth',1);
clabel(C,h,'color','k','labelspacing',60);
colorbar

 Accepted Answer

Voss
Voss on 10 Nov 2023
Edited: Voss on 10 Nov 2023
If you only need to see the plot from above (2d, xy view), then you can set Z to zero in the surf call but still use your Z for the surface colors. This makes the contour show up above the surface in the z-direction. (If your contour has negative values, use a number smaller (i.e., more negative) than anything in the contour for the surface Z instead of zero.)
X = 1:10;
Y = 1:10;
Z = 10*rand(10);
figure('Position',[1 1 700 1000])
subplot(2,1,1)
colormap(jet)
title('Original');
hold on;
grid on;
surf(X,Y,Z)
shading interp
[C,h] = contour3(X,Y,Z,'k','LineWidth',1);
clabel(C,h,'color','k','labelspacing',60);
colorbar
subplot(2,1,2)
levels = [0:1:15];
figure(1);
colormap(jet)
title('with surface Z = 0');
hold on;
grid on;
surf(X,Y,zeros(size(Z)),Z)
shading interp
[C,h] = contour3(X,Y,Z,'k','LineWidth',1);
clabel(C,h,'color','k','labelspacing',60);
colorbar

More Answers (0)

Categories

Products

Release

R2021b

Asked:

on 10 Nov 2023

Commented:

on 10 Nov 2023

Community Treasure Hunt

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

Start Hunting!