Effacer les filtres
Effacer les filtres

Colormap based on contour values

5 vues (au cours des 30 derniers jours)
Tyler Smith
Tyler Smith le 3 Mar 2017
Commenté : Tyler Smith le 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!

Réponse acceptée

Guillaume
Guillaume le 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
  1 commentaire
Tyler Smith
Tyler Smith le 3 Mar 2017
Works perfectly! Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by