Plotting data with different colour based on sign only

2 visualizaciones (últimos 30 días)
Suchetana Gupta
Suchetana Gupta el 3 de Jun. de 2015
Comentada: Guillaume el 3 de Jun. de 2015
I am trying to plot a set of data using the code:
data=xlsread('test_stress.xls');
imagesc(data');
%colormap([0 0 1; 1 0 0]); %blue; red
ax = gca;
ax.YTickLabel = {'7','10','36','46','54', '62', '63', '71', '82', '84', '90'};
colormap(bluewhitered(256)), colorbar
Now I am getting, as expected, a plot based on colour gradient. However what I want is that irrespective of the values, just based on the sign there should be a plot, i.e. whenever it is positive, it will be red and whenever negative, it should be blue. And zero gives white. How do I go about it?

Respuesta aceptada

Guillaume
Guillaume el 3 de Jun. de 2015
A simple way would be to change the CLim property of the axis. If you want white for 0, you also need to have it in the colormap:
imagesc(data');
colormap([0 0 1; 1 1 1; 1 0 0]);
ax = gca;
ax.CLim = [-eps; eps]; %Or hardcode some small enough constant

Más respuestas (1)

Walter Roberson
Walter Roberson el 3 de Jun. de 2015
imagesc(sign(data'));
colormap([0 0 1; 1 1 1; 1 0 0]);
  1 comentario
Guillaume
Guillaume el 3 de Jun. de 2015
Yes, actually it's simpler and I see no reason to plot the original data.

Iniciar sesión para comentar.

Categorías

Más información sobre Red 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