How to setup the colormap by myself?

1 view (last 30 days)
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

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!