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)

采纳的回答

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