How do I make a red and blue colormap?
124 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I can plot a matrix of integers using imagesc. How do I make a discrete colormap (i.e., only for the integers) with a gradient of red colors for positive values and a gradient of blue colors for negative values, with zero being white? Also, the numbers aren't symmetric about zero, i.e., they range from [-2,5] so I want a deep blue for -2 and a deep red for 5. I hope that makes sense.
0 Commenti
Risposta accettata
Star Strider
il 15 Set 2022
I am not exactly certain what you want, however the basic colormap is easy to create —
cm = [1 0 0; 1 1 1; 0 0 1]; % Basic Colormap
cmi = interp1([-2; 0; 5], cm, (-2:5)) % interpolated Colormap
M = randi([-2 5],9) % Matrix
figure
imagesc(M)
colormap(cmi)
Experiment to get different results.
.
2 Commenti
Più risposte (0)
Vedere anche
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!