surface plot face not showing colors corresponding to Zgrid in some areas

35 ビュー (過去 30 日間)
Shubham Kalode
Shubham Kalode 2020 年 11 月 20 日
編集済み: Bruno Luong 2020 年 11 月 21 日
I am trying to plot surface map with XYZ 2D arrays having all the correct data. However, after plotting the surface plot using the below highlighted code lines, the highlighted section in the plot is not showing the colormap corresponding the Zgrid values. At the highlighted section in the plot the Z values are greater than zero but the colormap in that section indicates color as zero value for z, which is not true.
Any ideas are welcome. What could be the issue?
s=surf(xGrid,yGrid,zGrid);
% xlim([min(X) 550])
% s.EdgeColor = 'none';
grid on
colormap(cool);
colorbar;
% set(gca,'colorscale','log');

回答 (2 件)

Cris LaPierre
Cris LaPierre 2020 年 11 月 21 日
編集済み: Cris LaPierre 2020 年 11 月 21 日
This has to do with how surface plots are created. For an alterante explanation, see this post.
Basically, your values are represented by the lines. The nodes (intersection of lines on x with lines on y) represent the values. The colored squares represent the space between your values. By default, MATLAB uses the previous node to determine the face color. Since the lower point of the area you highlighted is 0, the facecolor is 0.
Perhaps the simplest way around this is to change the default FaceColor property to 'interp'.
Z=zeros(6);
Z(3:4,3:4) = 1;
surf(Z,'FaceColor',"interp")
colormap jet
colorbar
view(3)
If that isn't acceptable, consider using a visualization technique where the squares are the values of your matrix. Two suggestions are heatmap and imagesc.

Bruno Luong
Bruno Luong 2020 年 11 月 21 日
編集済み: Bruno Luong 2020 年 11 月 21 日
Here is a workaround, keep flat facecolor. You can use mean/min instead of max depending on what is relevant for you.
Z=peaks(10);
subplot(2,2,1);
surf(Z);
title('Matlab assym color scheme')
% Cris LaPierre's answer
subplot(2,2,3);
surf(Z,'FaceColor','interp');
title('Interp color scheme')
Z3 = cat(3,Z(1:end-1,1:end-1),Z(2:end,1:end-1),Z(1:end-1,2:end),Z(2:end,2:end));
cfun = @(a) max(a,[],3);
CData = cfun(Z3);
subplot(2,2,2);
surf(Z,'CData',CData);
title('Max sym color scheme')
Z3 = cat(3,Z(1:end-1,1:end-1),Z(2:end,1:end-1),Z(1:end-1,2:end),Z(2:end,2:end));
cfun = @(a) mean(a,3);
CData = cfun(Z3);
subplot(2,2,4);
surf(Z,'CData',CData);
title('Mean sym color scheme')

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by