surface plot face not showing colors corresponding to Zgrid in some areas
28 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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');
0 Commenti
Risposte (2)
Cris LaPierre
il 21 Nov 2020
Modificato: Cris LaPierre
il 21 Nov 2020
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.
0 Commenti
Bruno Luong
il 21 Nov 2020
Modificato: Bruno Luong
il 21 Nov 2020
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')
0 Commenti
Vedere anche
Categorie
Scopri di più su Colormaps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!