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

6 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Star Strider
Star Strider il 28 Mar 2024
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 Commenti
Andrea Somma
Andrea Somma il 28 Mar 2024
Thank you very much! I suppose there is not easy way to prevent labels to overlap right?
Star Strider
Star Strider il 28 Mar 2024
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by