Colour range in a surfplot

2 visualizaciones (últimos 30 días)
Harry Porter
Harry Porter el 23 de Abr. de 2019
Comentada: Harry Porter el 24 de Abr. de 2019
Hi all,
I am trying to create a surfplot by using the following dataset:
X = [0.6944 1.0417 1.3889 1.7361 2.0833;
0.6944 1.0417 1.3889 1.7361 2.0833;
0.6944 1.0417 1.3889 1.7361 2.0833;
0.6944 0.7639 0.8333 1.0417 1.3194
0.6944 0.7639 0.8333 NaN NaN];
Y = [100 100 100 100 100;
80 80 80 80 80;
50 50 50 50 50;
30 30 30 30 30;
20 20 20 20 20];
Z = [9.9154 9.9154 13.2126 16.5108 19.6816;
9.9723 17.3669 18.0949 22.1746 26.1141;
2.5790 3.3976 4.2679 17.8651 79.8182;
8.9384 13.1504 17.8445 35.8271 114.3840;
48.1118 66.3772 82.9677 NaN NaN];
The code for the figure is as follows:
figure
surf(X,Y,Z)
colorbar
colormap(viridis)
xlabel('X','FontSize', 16)
ylabel('Y','FontSize', 16)
zlabel('Z','FontSize', 16)
ax = gca;
ax.FontSize = 14;
figure
contourf(X,Y,Z)
colorbar
colormap(viridis)
xlabel('X','FontSize', 16)
ylabel('Y','FontSize', 16)
zlabel('Z','FontSize', 16)
ax = gca;
ax.FontSize = 14;
The two figures I obtained are shown below:
Surfplot1.png Surfplot2.png
My question is:
The colour range in the first figure cannot be visualised properly due to the small dataset in the green and yellow ranges (see dataset and Figure 2). Is there a solution to resolve this problem? I have tried several other solutions such as caxis and meshgrid, but none of these solutions can help in improving the visualisation in the first figure.
Thank you for your suggestions in advance.

Respuesta aceptada

Kelly Kearney
Kelly Kearney el 23 de Abr. de 2019
By default, a surf plot uses faceted shading, which means that each face is a solid color, determined by a single vertex in that face. To get similar coloring as the contour plot, try interpolated shading instead:
figure
s = surf(X,Y,Z)
colorbar
colormap(viridis)
xlabel('X','FontSize', 16)
ylabel('Y','FontSize', 16)
zlabel('Z','FontSize', 16)
ax = gca;
ax.FontSize = 14;
shading interp;
set(s, 'edgecolor', 'k'); % if you still want the face edges visible
  1 comentario
Harry Porter
Harry Porter el 24 de Abr. de 2019
Hi Kelly,
Thank you for this excellent solution! It solved the problem described above.

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