Problem with surf plot shading - equal z values displayed as different colours

5 visualizaciones (últimos 30 días)
Hi,
I am generating a surface plot (MATLAB version 9.13) of some X,Y,Z data (example data stored in the attached mat file) and have noticed that the colours of the surface plot indicate different values of Z at points where Z has the same value. Please see the attached picture where two example (x,y) points, both corresponding to a z value of 2.356, are shaded in different yellow colours.
This plot was generated by:
figure
f1 = surf(X,Y,Z);
colorbar
view([0,90])
datatip(f1,X(2),Y(16));
datatip(f1,X(42),Y(16));
I would expect the shading to appear as in this scaled colour image:
figure
f2 = imagesc(Z);
colorbar
datatip(f2,2,16);
datatip(f2,42,16);
I would appreciate your help in understanding why I am seeing this discrepancy in the shading of the surface plot.
Many thanks,
Fiona

Respuesta aceptada

John D'Errico
John D'Errico el 16 de Feb. de 2023
Editada: John D'Errico el 16 de Feb. de 2023
This is likely simpler than you think. Or maybe not.
The colors for a surface are first chosen by a direct lookup into the current colormap. One color per patch. For example:
Z = [0 1 2;1 1 3];
surf(Z)
You should note there are only TWO patches shown there, each at a constant color, even though the array was a 2x3 array of values. So six colors are not shown. Only TWO different colors. Two patches, so two colors.
The level z of that surface is not constant over each patch. It varies considerably over the patches. However, if instead, I redraw the surface, but this time use an interpolated shading, now you see the difference across the two patches.
surf(Z)
shading interp
  1 comentario
Fiona N
Fiona N el 16 de Feb. de 2023
Thank you so much, this makes perfect sense of course and I appreciate your fast response on this.
Best wishes,
Fiona

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by