You can change the properties of the bar object to -1/0/1 with sign , and then use the binary red / blue color palette
y=rand(10,1)*3-1.5; % some data hb=bar(y); set(get(hb,'children'),'cdata', sign(y) ); colormap([1 0 0; 0 0 1]); % red & blue in rgb

You can find more information here .
EDIT: to obscure it, you need to install cdata accordingly in combination with caxis :
y=rand(10,1)*3-1.5; % some data hb=bar(y); % the colormap Mc = 16; Nc = Mc*2+1; % number of colors, uneven so there is a neutral middle rgb = [1 0 0;0 0 1]; cmap = [linspace(rgb(1,1),rgb(2,1),Nc)' linspace(rgb(1,2),rgb(2,2),Nc)' linspace(rgb(1,3),rgb(2,3),Nc)' ]; colormap(cmap); % cdata c = y; set(get(hb,'children'),'cdata', c); cmax = max(abs(c)); caxis([-cmax cmax]);

Gunther struyf
source share