How to use two colormaps in one imagesc plot?

I got a correlation map 50*50 with the data range [-0.8,1], I would like to plot the map using imagesc, and set the colormap based on the value range of each pixel, e.g for value >0 using 'hot' and for value<=0 using 'cool'. Is there a simple way to achieve this? Thanks in advance!

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 2 de Dic. de 2020
You can create a new colormap based on the proportion of the individual colormap
imagesc(M);
colorbar();
caxis([-0.8 1]);
cmap = [cool(80); hot(100)];
colormap(cmap);

4 comentarios

xw wang
xw wang el 2 de Dic. de 2020
Thanks~ The problem is the the proportion of the data is not always the same across all my correlation maps, and the value is double precision, so the actual range can be [-0.8123,0.9123], and the way you suggested is not easy to make the devision at 0, am I right?
You don't have to be super-precise. Something like this should work with a barely noticeable discrepancy
q = rand(1000)*1.8-0.8;
lims = [-0.8123, 0.9123];
imagesc(q);
colorbar();
caxis(lims);
lims = floor(abs(lims)*100);
cmap = [cool(lims(1)); hot(lims(2))];
colormap(cmap);
xw wang
xw wang el 2 de Dic. de 2020
Great, thanks, this seems a good way solving my problem, thanks a lot
Ameer Hamza
Ameer Hamza el 2 de Dic. de 2020
I am glad to be of help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 2 de Dic. de 2020

Comentada:

el 2 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by