Colormap based on contour values
2 views (last 30 days)
Show older comments
I want to make my color map such that it uses white for the 0 value and applies a diverging ramp of color (blue and red) for cmax and cmin. The example map I have is temperature anomalies. I can go through and manually adjust the RGB values so that white is 0, but I was hoping there was an easier way to automate the process so that the 0 value in the axis range is automatically white and the values diverge from there (either toward darker blue for negative or toward darker red for positive values). Any help would be great!
0 Comments
Accepted Answer
Guillaume
on 3 Mar 2017
function cmap = geblueredcolormap(cmin, cmax)
assert(cmin<0 & cmax> 0, 'colormap does not cross zero');
zeroidx = round(-cmin*255/(cmax-cmin));
bluesat = linspace(1, 0, zeroidx);
redsat = linspace(0, 1, 256-zeroidx);
hsv = [repmat([0 1 1], zeroidx, 1); repmat([2/3 1 1], 255-zeroidx, 1)];
hsv(:, 2) = [bluesat, redsat(2:end)];
cmap = hsv2rgb(hsv);
end
Will allow you to create the correct colormap
More Answers (0)
See Also
Categories
Find more on Blue 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!