How to setup the colormap by myself?

조회 수: 2 (최근 30일)
Tianming Qu
Tianming Qu 2022년 10월 17일
댓글: Bjorn Gustavsson 2022년 10월 18일
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

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by