Borrar filtros
Borrar filtros

How to make my own custom colormap?

163 visualizaciones (últimos 30 días)
Mark Golberg
Mark Golberg el 31 de En. de 2016
Comentada: 金山 el 10 de Mayo de 2024
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 comentario
Walter Roberson
Walter Roberson el 31 de En. de 2016
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?

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 31 de En. de 2016
Editada: Stephen23 el 1 de Feb. de 2016
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 comentarios
Daven Gooden
Daven Gooden el 13 de Ag. de 2020
WOW!!! Nicely Done!!!
金山
金山 el 10 de Mayo de 2024
awesome

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by