Why does "contourf" show a different color than the one meant for this value in my colorbar?

1 view (last 30 days)
If I run the code below a value of 800 for example is shown as the color at the bottom of the colorbar even if it should be the color for 800.
maxval=100;
cmax=1000;
xmax=maxval;
ymax=maxval;
X=linspace(0,xmax,xmax+1);
Y=linspace(0,ymax,ymax+1);
XY = zeros(xmax+1,ymax+1);
for x = X
for y = Y
XY(x+1,y+1)=x*y;
end
end
figure(1);
contourf(X,Y,XY);
grid on;
caxis([ 0 cmax ]);
colorbar;

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 Nov 2014
Your data consists of values between 0 and 10,000. "contourf" by default creates 9 linearly spaced contours. Hence the ranges are 0 to 1000, 1000 to 2000 and so forth. Since the value of 800 falls into the first area it is colored in the color belong to the lowest value in the range. In order to create contours for the range 0 to 1000, you can modify the "contourf" line of code as follows:
contourf(X,Y,XY,[0:100:1000]);

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2014b

Community Treasure Hunt

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

Start Hunting!