How to setup the colormap by myself?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tianming Qu
le 17 Oct 2022
Commenté : Bjorn Gustavsson
le 18 Oct 2022
Hi all,
I have a heat map as following attached, in which the dartk blue part is the part where the grid value equals to zero. Is there anyway I can set this zero value to color white and keep the reset color as colormap turbo? I want to show a clear edage between the zero value region and non-zero value region. Any answer would be helpful! Thanks!
Best
0 commentaires
Réponse acceptée
Bjorn Gustavsson
le 17 Oct 2022
You can combine one row of white and the turbo colormap:
cmp = [1,1,1;turbo];
colormap(cmp)
This leaves the problem with the exact alignment between the 0-level and the level-limit of the first row of the colormap.
You can simply set all the elements that are equal to zero to nan:
I2disp = I;
I2disp(I2disp(:)==0) = nan;
pcolor(I2disp([1:end,end],[1:end,end])),shading flat,axis ij
HTH
2 commentaires
Bjorn Gustavsson
le 18 Oct 2022
The first line simply creates a temporary variable that only is used for display-purposes - oftentimes preferable to leave the real data without modifications only for plotting. Here I assume that your original image are named I. Then we set all elements in that image that are equal to zero to nan. The (:) turns the array into a 1-D column-array. Then the equality-test pick out all the zero-elements. This type of indexing is very handy. Then the last line is just to display the image, instead of using imagesc it seems easier to use pcolor to get gaps where you have nan-values.
Plus de réponses (0)
Voir également
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!