Azzera filtri
Azzera filtri

Colormap based on contour values

5 visualizzazioni (ultimi 30 giorni)
Tyler Smith
Tyler Smith il 3 Mar 2017
Commentato: Tyler Smith il 3 Mar 2017
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!

Risposta accettata

Guillaume
Guillaume il 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

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by