Make a surface (interpolated colors) plot with contour lines over it
6 次查看(过去 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!