필터 지우기
필터 지우기

Color map from green to red

조회 수: 186 (최근 30일)
Idan Hamawi
Idan Hamawi 2020년 10월 17일
편집: DGM 2022년 4월 19일
Hi all,
I have a map with values and i would like to display the values with colors - from green to red.
The value closest to 0 will be green and the farthest will be red.
Example:
1, 5, 11, 33, 56, 100
1 - Green.
100 - Red.
Can be also:
-5, -23, -43, -55, -80.
-5 - Green.
-80 - Red.
The rest values will be in the order and color bar.

채택된 답변

Akira Agata
Akira Agata 2020년 10월 17일
You can create your original colormap (green to red) and apply to the data.
The following is an example:
% Create green-to-red colormap
cMap = interp1([0;1],[0 1 0; 1 0 0],linspace(0,1,256));
% Apply to the plot
surf(peaks)
colormap(cMap)
colorbar
  댓글 수: 4
Harpreet Singh
Harpreet Singh 2022년 4월 19일
But that is a one way gradient. Didn't Akira want a two way gradient? with gren being in the middle and red going outwards?
DGM
DGM 2022년 4월 19일
편집: DGM 2022년 4월 19일
I don't really think OP was after an RGB sweep, but more of an HSV hue sweep. Still, if Akira's solution was enough, then it could be made symmetric.
% Create red-green-red colormap
cMap = interp1(0:2,[1 0 0; 0 1 0; 1 0 0],linspace(0,2,256));
% Apply to the plot
surf(peaks)
colormap(cMap)
colorbar
FWIW, for simple RGB primary/secondary sweeps like this, you can improve the linearity to get rid of the dark bands:
% Create red-green-red colormap
cMap = interp1(0:1,[0 1 0; 1 0 0],linspace(0,1,256));
cMap = cMap.^(1/2.4); % linearize
% Apply to the plot
surf(peaks)
colormap(cMap)
colorbar
This gamma adjustment of colormaps can also be done using the misleadingly-named brighten() function, though the parameter behavior is (in my opinion) confusing in the degree to which it obfuscates the otherwise extremely simple math.
Gimme a minute and I'll whip up a colormap that replicates the exact map that OP posted.

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

추가 답변 (1개)

DGM
DGM 2022년 4월 19일
편집: DGM 2022년 4월 19일
This is how one might go about getting the exact colormap shown in the image and make a symmetric version of it.
A = imread('gyrcb.png');
imshow(A)
% get base color table from image
basect = im2double(permute(A(40,24:517,:),[2 3 1]));
N = 256;
nb = size(basect,1);
% interpolate to get a specified-length version
CT1 = interp1(1:nb,basect,linspace(1,nb,N));
% also make a symmetric version of the same length
CT2 = interp1(1:2*nb,[flipud(basect); basect],linspace(1,2*nb,N));
% Apply the new CT
surf(peaks)
colormap(CT1)
colorbar
% Apply the symmetric CT
figure
surf(peaks)
colormap(CT2)
colorbar
Similar questions:
colorbar extraction (a discrete colormap)
colorbar extraction (includes notes about dealing with compression artifacts)

카테고리

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