contour lines obscured on a surface.

3 次查看(过去 30 天)
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

采纳的回答

Voss
Voss 2023-11-10
编辑:Voss 2023-11-10
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by