MATLAB: Unevenly Map Data to an RGB Map

color mapplotting

So I have made an RGB style map that mimics Matlab's color map options (just a different flavor, for stylistic reasons), and I want it to scale to the bottom two thirds of my data. I want it to linearly scale to the bottom two thirds because the peaks are so high that a perfect linear match hides small-scale detail elsewhere in the figures. Any good tricks?
For context, I'm plotting with surfc and then:
load('rgbmap.mat'); %Homemade colormap stored here as variable "map"
colormap(map);
c = colorbar;
Thank you.

Best Answer

When you use a colormap, the entry-number used always scales linearly between the upper and lower limit established on the color axes (caxis) .
One approach is thus to create a colormap that conceptually spans the entire range of your data, but you repeat colors in the upper 1/3 (or as appropriate). It is completely valid to use a colormap that goes something like
black
red/8
2*red/8
3*red/8
4*red/8
yellow
yellow
yellow
blue
If you are using a sufficiently old MATLAB on MS Windows then you are limited to 256 entries in a colormap; other operating systems and newer MATLAB for Windows permit 65536 entries.
Another approach is to do the color mapping yourself. You can, for example, discretize() the Z range to get bin numbers, and ind2rgb(binNumbers, your_color_map) to get an RGB image. You can then set that as the CData of the surf() -- though I find that texture mapping like this is often easier to accomplish using warp() instead of surf() .