contourf plot value not corresponding to the legend bar value
Ältere Kommentare anzeigen
I have a general question about a contourf() plot that I am plotting. The plot is shown in the screenshot below. What I am confused about is why different z-value (Level, in this case) have the same color. The plot only have two colors, blue and red, while there are many different values ranging from .22 to .26. For example, with Level value of .26, I am expecting it to be black, according to the bar on the right hand side, and .255 to be darker blue, and .2575 to be black as well, but it's only one shade of blue. It looks like anything above .25 is blue, and anything below is red. Can anyone shine some light on what is happening?
Here is my code.
close('all'), clear, clc
f1 = figure;
ax = axes(f1);
load('data.mat')
smplX = reshape(smplX,[],1);
smplY = reshape(smplY,[],1);
smplZ = reshape(smplZ,[],1);
xLimits = [round(min(smplX)-1) round(max(smplX)+1)];
yLimits = [round(min(smplY)-1) round(max(smplY)+1)];
[xq,yq] = meshgrid(xLimits(1):0.5:xLimits(2),yLimits(1):0.5:yLimits(2));
zq2 = griddata(smplX,smplY,smplZ,xq,yq,'linear');
if any(isnan(zq2))
% zq3 = griddata(smplX,smplY,smplZ,xq,yq,'nearest');
% idx = isnan(zq2);
% zq2(idx)=zq3(idx);
zq2 = griddata(smplX,smplY,smplZ,xq,yq,'nearest');
end
contourf(ax,xq,yq,zq2);
c = colormap(ax,flipud(turbo()));
ax.CLim = [0.22 max(zq2,[],'all')];
cInc = (ax.CLim(2)-ax.CLim(1))/256;
cInc = round((0.25 - ax.CLim(1))/cInc);
if cInc>size(c,1)
cInc = size(c,1);
disp(size(c,1));
end
% rectangle(ax,'Position',[-xLimits(1) yLimits(1) ...
% xLimits(2)-xLimits(1) ...
% yLimits(2)-yLimits(1)],...
% 'FaceColor',...
% c(cInc,:),'LineWidth',2)
ax.XLimitMethod = "tight";
ax.YLimitMethod = "tight";
ax.Children = ax.Children(end:-1:1);
colorbar(ax,"eastoutside")
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Contour Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


