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)
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!