How to make my own custom colormap?
144 ビュー (過去 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
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
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 Center および File Exchange で Colormaps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!