In this MATLAB video we show how you can manipulate the clim property of an axis to determine the points that an image will saturate the colormap. This is often a better choice than making a strange colormap to get the same effect.
By
Doug Hull
Doug first used MATLAB in 1994, could not figure it out until he got some help in 1995. He is now dedicated to making sure that no one else wastes a year of their life not knowing MATLAB like he did.
I have a related question. I have used the function you wrote “makeColorMap” to make a colormap that goes smoothly from red to white to blue. Now suppose I want to make sure that red shades are for negative numbers, blue shades are for positive numbers and any zero contours would be white. Is there a simple way to anchor white to the zero level?
You can set the clim as specified in the movie. Make those limits such that the white value of colormap happens to fall on zero. So it is slightly indirect, takes a little bit of math, but should not be difficult. Especially if it is a symmetric colormap, just choose the clims to be equidistant from zero.
If the colorbar is not symmetric you could calculate the difference between the signed most negative and most positive values in your data and use both the numerical result and its sign to assign the limits of saturation automatically. this should anchor it to zero.
Something like the below “pseudocode”:
if D maxpos+maxneg >0 % abs(maxpos) > abs (maxneg)
clim=[maxneg (maxpos-D)]
elseif
D = maxpos+maxneg <0
clim=[(maxneg-D) (maxpos)]
end
Leave a Reply
About
Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.
I have a related question. I have used the function you wrote “makeColorMap” to make a colormap that goes smoothly from red to white to blue. Now suppose I want to make sure that red shades are for negative numbers, blue shades are for positive numbers and any zero contours would be white. Is there a simple way to anchor white to the zero level?
@Roy,
You can set the clim as specified in the movie. Make those limits such that the white value of colormap happens to fall on zero. So it is slightly indirect, takes a little bit of math, but should not be difficult. Especially if it is a symmetric colormap, just choose the clims to be equidistant from zero.
Doug
Roy,
If the colorbar is not symmetric you could calculate the difference between the signed most negative and most positive values in your data and use both the numerical result and its sign to assign the limits of saturation automatically. this should anchor it to zero.
Something like the below “pseudocode”: