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

38 views (last 30 days)
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
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?

Answers (2)

David Goodmanson
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.
Image Analyst
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.

Sign in to comment.

Image Analyst
Image Analyst on 25 Aug 2021
To make any part of any colormap white, set the 3 values to 1:
grayImage = 1.5 * im2double(imread('cameraman.tif'));
% See what we get with default colormap.
myCustomColormap = hot(256);
subplot(1, 2, 1);
imshow(grayImage, [], 'ColorMap', myCustomColormap)
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)
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.


Find more on Colormaps in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by