how to create and use mixed colormaps associated to positive and negative data values?

조회 수: 11 (최근 30일)
For example I have a 2D matrix with values from [-100,200]. I would like to plot positive values from white to black, and negative values from blue to red.

채택된 답변

Kelly Kearney
Kelly Kearney 2015년 8월 7일
I like using .cpt files for specific colormaps like this, with the cptcmap.m function:
cdata = [...
-100 0 0 255 0 255 0 0
0 255 255 255 200 0 0 0];
dlmwrite('mycmap.cpt', cdata, ' ');
axes;
imagesc(rand(100)*300 - 100);
cptcmap('mycmap', 'mapping', 'direct');
colorbar;

추가 답변 (1개)

Abhishek Pandey
Abhishek Pandey 2015년 8월 7일
Hello,
I understand that you want to plot a 2D matrix with colors from white to black for positive values and blue to red for negative values. Also, the values range from -100 to 200.
I believe you could do this by creating two different matrices, one which contains the positive values and other one containing the negative values. You can set the rest of the entries in these matrices to NaN.
For the matrix containing positive values, set the ‘colormap’ to ‘gray’ and plot it in a figure. After this, set the ‘colormap’ to ‘jet’ and plot the other matric on the same figure using the “hold on” command.
For more information about how to set the ‘colormap’, you can refer to the following documentation link:
I hope this helps!
- Abhishek
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 8월 7일
If the images are in the same axes then the colormap jet will change the colormap interpretation of the gray things already plotted, even in current versions of MATLAB. In R2014a or earlier, the same thing would happen if the two colormaps are in the same figure.
The File Exchange contribution freezeColors() can be useful for things like this.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by