필터 지우기
필터 지우기

How to make my own custom colormap?

조회 수: 163 (최근 30일)
Mark Golberg
Mark Golberg 2016년 1월 31일
댓글: 金山 2024년 5월 10일
Hello, how can I define my colormap to be with the following steps: (those are hex colors)
100% - #f8fe34
83% - #f4771e
68% - #d94015
44% - #148b3e
30% - #085a3f
15% - #41332d
0% - #010101
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 1월 31일
Do you want graduations between the adjacent ones, or solid colors and then a jump? So for example would you have
cmapsize = 256; %or as passed in
NumPoints = floor(cmapsize * 15/100) - floor(cmapsize * 0/100);
part0 = [linspace(dec2hex('01'), dec2hex('41'), NumPoints).', ...
linspace(dec2hex('01'), dec2hex('33'), NumPoints).', ...
linspace(dec2hex('01'), dec2hex('2d'), NumPoints).']
as part of the construction?

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

채택된 답변

Stephen23
Stephen23 2016년 1월 31일
편집: Stephen23 2016년 2월 1일
Step 1: Convert HEX to Decimal
>> hex = ['#f8fe34';'#f4771e';'#d94015';'#148b3e';'#085a3f';'#41332d';'#010101']
hex =
#f8fe34
#f4771e
#d94015
#148b3e
#085a3f
#41332d
#010101
>> map = sscanf(hex','#%2x%2x%2x',[3,size(hex,1)]).' / 255
map =
0.97255 0.99608 0.20392
0.95686 0.46667 0.11765
0.85098 0.25098 0.082353
0.078431 0.5451 0.24314
0.031373 0.35294 0.24706
0.2549 0.2 0.17647
0.0039216 0.0039216 0.0039216
>> rgbplot(map) % to view the values
The matrix map is a standard MATLAB colormap, and it can be used anywhere that you need a colormap. You could also interpolate its values (if you need more nodes), or set this as your default colormap, or many other operations.
Step 2: Interpolate
If you want to interpolate the colormap and place the specified nodes at the given "percent" locations:
vec = [ 100; 83; 68; 44; 30; 15; 0];
hex = ['#f8fe34';'#f4771e';'#d94015';'#148b3e';'#085a3f';'#41332d';'#010101'];
raw = sscanf(hex','#%2x%2x%2x',[3,size(hex,1)]).' / 255;
N = 128;
%N = size(get(gcf,'colormap'),1) % size of the current colormap
map = interp1(vec,raw,linspace(100,0,N),'pchip');
which looks like this:
  댓글 수: 5
Daven Gooden
Daven Gooden 2020년 8월 13일
WOW!!! Nicely Done!!!
金山
金山 2024년 5월 10일
awesome

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by