contour lines on the surface plot

46 Ansichten (letzte 30 Tage)
Masa
Masa am 6 Feb. 2022
Beantwortet: Masa am 7 Feb. 2022
How to plot a surface with its contour lines drawn on it?
this image is an example of what I mean:

Akzeptierte Antwort

Star Strider
Star Strider am 6 Feb. 2022
Try something like this —
[X,Y,Z] = peaks(50); % Example Surface
figure
surf(X,Y,Z, 'EdgeColor','none') % Surface Plot
hold on
contour3(X,Y,Z,10, '-k', 'LineWidth',1.5) % Add Contours
hold off
grid on
colormap('jet')
shading('interp')
view(30,45)
See the documentation on surf and contour3 for details.
Make appropriate changes to get the desired result.
.

Weitere Antworten (1)

Masa
Masa am 7 Feb. 2022
for those who need the same plot but with discrete colors (corresponding to the levels of the contour plot):
% surface data to plot
[X,Y,Z] = peaks(50);
% plot surface
surf(X,Y,Z);
shading('interp');
hold on;
% plot contours
contourLevelsNum = 9;
contour3(X,Y,Z,contourLevelsNum,'k');
hold off;
colormap(jet(contourLevelsNum+1));
cb = colorbar;
% correct position of ticks in the color bar
[zDataMin, zDataMax] = bounds(Z(:));
caxis([zDataMin,zDataMax]);
set(cb,'Ticks',linspace(zDataMin,zDataMax,contourLevelsNum+2));
view(30,45);

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by