필터 지우기
필터 지우기

Make a surface (interpolated colors) plot with contour lines over it

조회 수: 3 (최근 30일)
I wanto to make a plot like the one in the image:
The code I tried is below, but the contours dont properly show (hidden below the surface)
surface(XX, YY, F, 'edgecolor', 'none')
hold on
contour(XX,YY,F,3,'-k','showText',true)

채택된 답변

Star Strider
Star Strider 2024년 3월 28일
You can use a surfc plot with tweks to the contour plot, and an appropriate view call —
[X,Y,Z] = peaks(250);
figure
hs = surfc(X, Y, Z, 'EdgeColor','interp');
hs(2).LabelFormat = '%.3f';
hs(2).ZLocation = 'zmax';
hs(2).ShowText = 'on';
hs(2).LineStyle = '-';
hs(2).LineColor = 'k';
colormap(turbo)
view(0,90)
The problem is that unlike the contour function, the contour labels are not aligned well with the contour lines. That can be adjusted (with additional and definitely non-trivial programming) that would require locating the lables and then rotating them appropriately.
.
  댓글 수: 6
Andrea Somma
Andrea Somma 2024년 3월 28일
Thank you very much! I suppose there is not easy way to prevent labels to overlap right?
Star Strider
Star Strider 2024년 3월 28일
As always, my pleasure!
Unfortunately, no, or at least not to my knowledge when they are as close as they are here. There is a LabelSpacing property, however that would probably not solve the overlap problem, since that is their spacing along the contour lines, and it is not possible (at least to my knowledge) to set that individually for each contour.
It might be possible to change the label font size, since I suspect that they are text objects (the documentation notes that they are created by the compose function), however I will have to look into that. It is not part of the documented properties, and could require some property spelunking to find it. If I can find it and change it, I will post back here with that information.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by