Colour range in a surfplot

조회 수: 1 (최근 30일)
Harry Porter
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.

채택된 답변

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