Contour plot on top of surface plot
Mostrar comentarios más antiguos
Hi all,
I want to achieve something like the attached picture. I have tried with a mesh on top of a surf plot without success. I am not sure if this can be achieved with the surfc function. Any hints?
Thanks

Respuesta aceptada
Más respuestas (2)
Jacob Wood
el 21 de Feb. de 2020
You can get similar results with surf() and contourf()
[X,Y,Z] = peaks(25);
surf(X,Y,Z-10)
hold on
contourf(X,Y,Z)

Walter Roberson
el 21 de Feb. de 2020
Editada: Walter Roberson
el 21 de Feb. de 2020
0 votos
Although it is possible to hack the properties of contour to change where the z values appear, it is typically much easier to create a hgtransform() group, and when you contour() use that group's handle as the first parameter to contour() (the position you would specify the axes). Then set the transform matrix of the hgtransform group to translate Z upwards by however many units are appropriate. If you use datatips, then they will reflect the original data values, not the translated values.
The code suggested by Jacob Wood does work for its purpose, and can be used with contour() as well as contourf(), but it relies upon subtracting enough from the Z coordinates that all of the Z coordinates passed to surf() are negative. Then you either have to live with the z axes be offset by that subtracted amount, or else you have to set the Z tick labels to hide the fact that your data is offset. Your ability to use datatips is affected when you use this approach.
4 comentarios
Geraldo Rebouças
el 5 de Jul. de 2022
could you please provide an example explaining how to do it using hgtransform?
[X,Y,Z] = peaks(25);
surf(X,Y,Z)
hold on
hgt = hgtransform();
hgt.Matrix = makehgtform('translate', [0 0 7])
contourf(X, Y, Z, 'parent', hgt)
Geraldo Rebouças
el 6 de Jul. de 2022
Thanks!
Geraldo Rebouças
el 27 de Nov. de 2023
@Walter Roberson, I was wondering if you could help me with this one:
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
