I would like a colorbar that only shows the colors of numbers that exist in the dataset.
Example:
x = -2*pi:0.01:2*pi;y = x;[X Y] = meshgrid(x,y);Z = sign(round(cos(X).*cos(Y)));imagesc(x,y,Z);colorbar;
There are only 3 possible numbers in the output matrix. Unfortunately, the colorbar will still show a full gradient.
I would appreciate a method for generating a colorbar with only the levels that are present.
Best Answer