Question for color set in colorbar

2 visualizaciones (últimos 30 días)
aurc89
aurc89 el 30 de Mzo. de 2020
Comentada: Ameer Hamza el 30 de Mzo. de 2020
Hello,
I plot an image using imagesc, and the colorbar is automatically set from blue (lowest value, e.g. 0) to red (highest value, e.g. 1). Is there a way to set the interval color from white (lowest value) to red (highest value) ?
Thanks

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 30 de Mzo. de 2020
Editada: Ameer Hamza el 30 de Mzo. de 2020
You can also create you custom colormap
White = [1 1 1];
Red = [1 0 0];
t = linspace(0,1,100)';
cmap = Red.*t + White.*(1-t);
colormap(cmap);
colorbar
  6 comentarios
aurc89
aurc89 el 30 de Mzo. de 2020
Now it works! Thanks!
Ameer Hamza
Ameer Hamza el 30 de Mzo. de 2020
Glad to be of help.

Iniciar sesión para comentar.

Más respuestas (2)

darova
darova el 30 de Mzo. de 2020
Yes, there is a way. Use colormap
cmap = hot(100);
colormap(cmap(30:end,:)) % i use only last 70 values because first 30 is too dark
colorbar
  1 comentario
aurc89
aurc89 el 30 de Mzo. de 2020
Thanks! But this gives the opposite (dark=minimum, white=maximum), what if I want the reversed one (white=minimum, dark=maximum) ?

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 30 de Mzo. de 2020
Try this:
grayImage = imread('cameraman.tif');
white = [1 1 1];
red = [1 0 0];
imagesc(grayImage);
ramp = linspace(0, 1, 256)';
ramp = [ramp, ramp, ramp];
customColorMap = red .* ramp + white .* (1-ramp);
colormap(customColorMap);
colorbar
  1 comentario
aurc89
aurc89 el 30 de Mzo. de 2020
I see the image but the code gives error, I think it's due to my previous version of Matlab.
Thanks anyway! I think it works now

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by