How do I make the colorbar of my image plot in matlab to get discrete values without only giving colour to parts of my data

Viewed 553

I am plotting a matrix with rain intensities with an image plot in matlab.

I want the colorbar to show a distinct colour for 0-10, 10-20... to 90-10.

I've tried the function surf(10) to get 10 discrete colors, but then only values up 10 is showed.

This is the code I used:

image(pr20020719T0730)
cmap = jet(10);
colormap(cmap);
colorbar

This is how the image looks after the code

1 Answers

Unlike imshow, the image function sets the CDataMapping property of the image object to 'direct'. Read MATLAB docs for more details. This is how this affects the outcome:

% create 256x256-matrix with discrete, ascending column values
X = repmat(linspace(0, 100, 256), 256, 1);
% first subplot
subplot 121
image(X)
colorbar
% second subplot
subplot 122
image(X, 'CDataMapping', 'scaled')
colorbar

% set colormalt to "jet"
cmap = jet(10);
colormap(cmap)

enter image description here

Related