Colormap based on contour values

5 次查看(过去 30 天)
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!

采纳的回答

Guillaume
Guillaume 2017-3-3
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by