# Change the hot colormap so that the default value of 1 is white

38 views (last 30 days)
Matthew Kehoe on 24 Aug 2021
Commented: Image Analyst on 25 Aug 2021
Inside my Matlab code I am using the hot colormap in order to produce plots of the calculated reflectivity.
Example 1: Subset of the reflectivity map. The hot colormap seems to set the color of the value 1 at random (in this case, it is orange).
Example 2: Another subset of the reflectivity map. Now 1 is yellow instead of orange.
How can I change my Matlab code so that the value of R=1 is always set to the white color inside the colorbar and the colormap? My current code calls the colorbar and colormap by
% do a bunch of calculations
figure(1);
colorbar; colormap hot;
% I don't specify additional code to adjust the hot colorbar or colormap
Can I adjust this code so that R=1 is white by default?
##### 2 CommentsShowHide 1 older comment
Susmita Panda on 24 Aug 2021
You can try flipud(hot) it will invert the color of the hot.

David Goodmanson on 25 Aug 2021
Hi Matthew,
The 'hot' colormap has white at one end of its scale and almost-black at the other. Suppose you successfully change things so that R=1 is white. What do you want to happen for values of R that are greater than 1, which occur in both plots?
If you are ok with all values of R >=1 mapping to white, then using the line
caxis([Rmin 1])
just after the plot command does so, where Rmin is the minimum value of R over the entire set of x,y values.
##### 2 CommentsShowHide 1 older comment
Image Analyst on 25 Aug 2021
@Matthew Kehoe, my code below can easily be modified to have all values above 1 be white (instead of only the value that's closest to 1 be white) if that's what you want.

Image Analyst on 25 Aug 2021
To make any part of any colormap white, set the 3 values to 1:
% See what we get with default colormap.
myCustomColormap = hot(256);
subplot(1, 2, 1);
imshow(grayImage, [], 'ColorMap', myCustomColormap)
colorbar;
colorBarLimits = caxis
% Find rows where value = 1
rowFor1 = round(interp1(colorBarLimits, [1, size(myCustomColormap, 1)], 1.0))
% Make that row of the colormap white:
myCustomColormap(rowFor1, :) = 1;
% See what we get with changed colormap.
subplot(1, 2, 2);
imshow(grayImage, [], 'ColorMap', myCustomColormap)
colorbar;
Note that the image values go from 0 to 1.5 and I used a hot colormap, but I found out what row of the color map corresponds to a gray level of 1 and I set that row of the colormap to white (all 1's). See the white line in the colorbar on the right and how some of the pixels in the image on the right are now white where they used to be orange.

### Categories

Find more on Colormaps in Help Center and File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by