MATLAB Answers

0

Colour range in a surfplot

Harry Porter さんによって質問されました 2019 年 4 月 23 日
最新アクティビティ Harry Porter さんによって コメントされました 2019 年 4 月 24 日
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.

  0 件のコメント

サインイン to comment.

1 件の回答

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 件のコメント

Hi Kelly,
Thank you for this excellent solution! It solved the problem described above.

サインイン to comment.



Translated by