Colour range in a surfplot

1 次查看(过去 30 天)
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.

采纳的回答

Kelly Kearney
Kelly Kearney 2019-4-23
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 个评论
Harry Porter
Harry Porter 2019-4-24
Hi Kelly,
Thank you for this excellent solution! It solved the problem described above.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by