How to setup the colormap by myself?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tianming Qu
am 17 Okt. 2022
Kommentiert: Bjorn Gustavsson
am 18 Okt. 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 Kommentare
Akzeptierte Antwort
Bjorn Gustavsson
am 17 Okt. 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 Kommentare
Bjorn Gustavsson
am 18 Okt. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Color and Styling finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!