How to setup the colormap by myself?

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Bjorn Gustavsson
Bjorn Gustavsson il 17 Ott 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 Commenti
Tianming Qu
Tianming Qu il 17 Ott 2022
Hi,
Thanks. This helps. Could you explain more about your second part code?
Bjorn Gustavsson
Bjorn Gustavsson il 18 Ott 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.

Accedi per commentare.

Più risposte (0)

Categorie

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

Tag

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by