Search code examples
matlabmatlab-figurecolormap

How map data values to colormap/colobar in Matlab


I have some troubles when trying to adapt the values of my data to the colormap intensity. In particular I want to set the min value and the max value in corrispondence of the white and the black color. I tried with colormap(flipud(gray)) that creates the rights scale of colors, but the limits the colorbar shows are [0,2]. If I manually set limit with colorbar('Limits',[0,1]) the colorbar shows correctly the limits but the colormap is now in a scale from white to grey (and not black). How to handle this?


Solution

  • The colormap will automatically be set to the values of your data. Your data is [0 2] in range, therefore its set to that. To do what you want, you need to saturate your colormap, it will mean that it will plot from white to black at [0 1] but it will be just black at [1 2]. In general, this is bad science, you are misleading the reader about the actual value of the surface/image.

    However, if you have a genuine reason to do it, then the command is caxis([0 1])