How to make my own custom colormap?

117 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(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