MATLAB: Plotting data with different colour based on sign only

plotting imagesc colorbar

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?

Best Answer

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